NativeScript 8.2:找不到名称 CLLocationManager、CLLocationManagerDelegate

NativeScript 8.2 : Cannot find name CLLocationManager, CLLocationManagerDelegate

我想在我的 NativeScript 应用程序版本 8 中这样调用 ios 本机 api

import { Injectable } from "@angular/core";

import * as geoLocation from "nativescript-geolocation";

import { Logger } from "../../shared/default-logger.service";

import { LocationServiceBase } from "./location.service.common";



@Injectable()

export class LocationService extends LocationServiceBase {



    private iosLocManager: CLLocationManager;

    private locManagerDelegate: LocationMangerDelegate;



    constructor(private logger: Logger) {

        super(logger);

        this.iosLocManager = new CLLocationManager();

        this.locManagerDelegate = new LocationMangerDelegate();

        this.iosLocManager.desiredAccuracy = 3;

        this.iosLocManager.distanceFilter = 0.1;

        this.logger.log("before setting delegate");

        this.iosLocManager.delegate = this.locManagerDelegate;

        this.logger.log("after setting delegate");

    }





    protected getDirection(location: geoLocation.Location): number {

        return this.locManagerDelegate.currentHeading;

    }



    startUpdatingHeading(): void {

        this.locManagerDelegate.currentHeading = null;

        this.iosLocManager.startUpdatingHeading();

    }



    stopUpdatingHeading(): void {

        this.iosLocManager.stopUpdatingHeading();

    }

}



export class LocationMangerDelegate extends NSObject implements CLLocationManagerDelegate {

    public static ObjCProtocols = [CLLocationManagerDelegate]; // tslint:disable-line:variable-name



    currentHeading: number;



    locationManagerDidUpdateHeading(locationManager: CLLocationManager, heading: CLHeading): void {

        this.currentHeading = heading.trueHeading;

    }



}

在 NativeScript 版本 6 CLLocationManager 中,CLLocationManagerDelegate 在 tns-platform-declarations 中可用,但在新版本 8 中没有 tns-platform-declarations 包,它被替换为@nativescript/types。

而且@nativescript/types包中没有CLLocationManager、CLLocationManagerDelegate,我如何在新版本中使用它们?

Package.json

{
  "license": "SEE LICENSE IN <your-license-filename>",
  "repository": "<fill-your-repository-here>",
  "dependencies": {
    "@angular/animations": "~13.2.0",
    "@angular/common": "~13.2.0",
    "@angular/compiler": "~13.2.0",
    "@angular/core": "~13.2.0",
    "@angular/forms": "~13.2.0",
    "@angular/http": "8.0.0-beta.10",
    "@angular/platform-browser": "~13.2.0",
    "@angular/platform-browser-dynamic": "~13.2.0",
    "@angular/router": "~13.2.0",
    "base-64": "^0.1.0",
    "cross-env": "^5.2.0",
    "lodash": "^4.17.11",
    "@nativescript/angular": "^13.0.0",
    "@nativescript/appversion": "2.0.0",
    "@nativescript/camera": "5.0.10",
    "nativescript-couchbase": "^1.0.18",
    "@nativescript/email": "2.0.5",
    "@nativescript/geolocation": "8.0.2",
    "nativescript-orientation-free": "2.2.5",
    "nativescript-phone": "3.0.3",
    "nativescript-screen-orientation": "^2.0.0",
    "nativescript-theme-core": "~1.0.4",
    "reflect-metadata": "~0.1.13",
    "rxjs": "~7.5.0",
    "rxjs-compat": "^6.4.0",
    "utf8": "^3.0.0",
    "zone.js": "~0.11.5",
    "@nativescript/core": "~8.2.0"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~13.2.0",
    "@nativescript/schematics": "~0.5.0",
    "@ngtools/webpack": "~13.2.0",
    "@nativescript/webpack": "5.0.6",
    "@angular-devkit/build-angular": "~13.2.0",
    "@nativescript/ios": "8.2.1",
    "@nativescript/types": "~8.2.0",
    "typescript": "~4.5.5"
  },
  "readme": "NativeScript Application",
  "main": "./src/main.ts"
}

reference.d.ts

/// <reference path="./node_modules/@nativescript/types/index.d.ts" />

tsconfig.json

{
    "compilerOptions": {
        "module": "esnext",
        "target": "es2017",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noEmitHelpers": true,
        "noEmitOnError": true,
       "skipLibCheck": true,
       "skipDefaultLibCheck": true,
        "lib": [
            "dom",
            "es2017"
        ],
        "baseUrl": ".",
        "paths": {
            "~/*": ["src/*"],
            "@/*": ["src/*"]
          },
        "moduleResolution": "node",
        "removeComments": false
    },
    "include": [ "src/**/*.ios.ts"],
    "files": ["./src/main.ts", "./reference.d.ts","./src/polyfills.ts"],
    "exclude": [
        "node_modules",
        "platforms"
    ]
}

在此处输入代码

尝试“@nativescript/types”插件版本 8.1.1。我和 8.2.0 有同样的问题。

我的 references.d.ts 文件中也有这些行。

<reference path="./node_modules/@nativescript/types-ios/index.d.ts" />
<reference path="./node_modules/@nativescript/types-android/index.d.ts" />