首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >didUpdateHeading方法在NativeScript 8.2中未被调用

didUpdateHeading方法在NativeScript 8.2中未被调用
EN

Stack Overflow用户
提问于 2022-03-30 17:50:31
回答 1查看 43关注 0票数 -1

我正在尝试使用iOS,CLLocationManager,CLLocationManagerDelegate在本地文本CLLocationManagerDelegate应用程序中获取标题值。

LocationService.ts

代码语言:javascript
复制
import { Injectable } from "@angular/core";

@Injectable()
export class LocationService {
    
    private locationManager : CLLocationManager;
    constructor() {
        this.locationManager = CLLocationManager.alloc().init();
        this.locationManager.desiredAccuracy = 3;
        this.locationManager.distanceFilter = 0.1;
        this.locationManager.headingFilter = 0.1;
        this.locationManager.delegate = new LocationMangerDelegate();
        this.locationManager.requestWhenInUseAuthorization();
        this.locationManager.requestAlwaysAuthorization();
    }

    requestLocation(): void{
        this.locationManager.requestLocation();
    }

    startUpdatingLocation(): void {
        this.locationManager.startUpdatingLocation();
      }

      startUpdatingHeading(): void {
        this.locationManager.startUpdatingHeading();
      }
} 

class LocationMangerDelegate extends NSObject implements CLLocationManagerDelegate {
    public static ObjCProtocols = [CLLocationManagerDelegate];

    locationManagerDidUpdateLocations(manager: CLLocationManager, locations: NSArray<CLLocation> | CLLocation[]): void{
        console.log('we are in');
    };


    public locationManagerDidFailWithError(manager: CLLocationManager, error: NSError): void{
        console.log('error');
    };

    public locationManagerDidUpdateHeading(manager: CLLocationManager, newHeading: CLHeading): void{
        console.log('updated heading');
    };

    public locationManagerShouldDisplayHeadingCalibration(manager: CLLocationManager): boolean{
        console.log('header calibration');
        return true;
    };
}

TestComponent.ts

代码语言:javascript
复制
import { LocationService } from "../shared/location.service";

export class TestComponent implements OnInit{
    

    constructor(
        private locationService: LocationService) {
        this.locationService.startUpdatingHeading();
    }

Info.plist

代码语言:javascript
复制
<key>UIRequiredDeviceCapabilities</key>
        <array>
          <string>magnetometer</string>
            <string>gps</string>
      <string>location-services</string>
            <string>armv7</string>
        </array>
    
    <key>NSLocationWhenInUseUsageDescription</key>
        <string>Desc</string>
        <key>NSLocationAlwaysUsageDescription</key>
        <string>Des1</string>
        <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
        <string>Des7</string>
       <key>NSLocationUsageDescription</key>
       <string>Desc123</string>

reference.d.ts

代码语言:javascript
复制
/// <reference path="./node_modules/@nativescript/types-ios/complete.d.ts"/>

当我从组件调用startUpdatingHeading方法时,不会触发LocationMangerDelegate类中的locationManagerDidUpdateHeading()方法。

我怎么才能把这事做好?我被困在这里,无法继续前进。

EN

回答 1

Stack Overflow用户

发布于 2022-04-05 19:11:14

I能够使用

代码语言:javascript
复制
   private locationManager : CLLocationManager;
   constructor() {
      this.locationManager = CLLocationManager.alloc().init();
      this.locationManager.desiredAccuracy = 3;
      this.locationManager.distanceFilter = 0.1;
      this.locationManager.headingFilter = 0.1;
    }
    
    getDirection(): number {
    return this.locationManager?.heading?.trueHeading === undefined ? -1 :          this.locationManager?.heading?.trueHeading;
}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71681893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档