【问题标题】:How to detect compass calibration switch state on iOS如何在 iOS 上检测指南针校准开关状态
【发布时间】:2012-11-23 10:44:37
【问题描述】:

我目前正在使用CLLocationManager 并希望了解设备的当前航向。到目前为止一切正常,功能已实现,现在我尝试完善我的应用程序。

有一个极端情况,如果用户关闭用户设置标题中的compass calibration 标志,更新将不会再发送到我的应用程序。在这种情况下,我想给用户一些反馈,他必须再次打开指南针校准,否则我的应用程序将无法运行。

我发现如果用户为我的应用关闭location services,我仍然会收到磁航向。但是,如果用户关闭“指南针校准”设置,我将不再收到任何航向更新。但是如何通过CoreLocation 框架识别“指南针校准”已关闭?

CLLocationManagerDelegate”通过

向我提供更新
- (void)locationManager:(CLLocationManager*)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status 

方法。但状态仅表明“位置服务”是否对我的应用程序处于非活动/活动状态。

我也尝试通过

获取一些有效信息
- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error

delegate 方法,没有任何成功。

CoreLocation 框架中有什么东西可以告诉我“指南针校准”标志是否打开/关闭。

【问题讨论】:

  • 你找到答案了吗?

标签: ios core-location cllocationmanager heading


【解决方案1】:

根据我的发现,如果指南针校准已关闭,locationManager:didUpdateHeading: 中的 newHeading.trueHeading 应该是 -1。应该这样做:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    if(newHeading.trueHeading == -1)
        //Compass calibration is off provided location services are on for the app
}

【讨论】:

  • 谢谢!这正是我所需要的。我没有直接在我的应用程序中使用标题(我使用的是 Core Motion),所以我什至没有实现 didUpdateHeading 方法,也没有仔细查看相应的文档。
  • 但请注意,即使在打开指南针校准的情况下,trueHeading 在启动过程中也是-1。
猜你喜欢
  • 1970-01-01
  • 2013-06-09
  • 2020-03-27
  • 2015-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多