首页 > 解决方案 > 无法从核心位置回调请求指南针校准

问题描述

我在我的应用程序中使用核心位置,并且在设备罗盘/航向值太不精确时尝试显示校准警报。

我正在从 didUpdateHeading 委托函数中正确读取标题值。

我阅读了相关帖子和 CLLocationManager 文档(https://developer.apple.com/documentation/corelocation/cllocationmanagerdelegate/1621457-locationmanagershoulddisplayhead)。

在 locationManagerShouldDisplayHeadingCalibration(_:) 委托函数中,我尝试了这两种实现:

func locationManagerShouldDisplayHeadingCalibration(_ manager: CLLocationManager) -> Bool {
    return true
}

和:

func locationManagerShouldDisplayHeadingCalibration(_ manager: CLLocationManager) -> Bool {
    print("locationManagerShouldDisplayHeadingCalibration")
    if let h = manager.heading {
        return h.headingAccuracy < 0 || h.headingAccuracy > 10
    }
    return true
}

在文档中,声明“如果您从此方法返回 false 或未在您的委托中为其提供实现,则核心位置不会显示航向校准警报。即使未显示警报”,但我没有不知道如何“为其提供实现”。

此外,我发现没有办法手动显示系统校准警报,如果警报没有按我想要的频率显示,那么轮询 didUpdateHeading 回调中的 headingAccuracy 值并显示类似系统的方法是否是一个很好的解决方案警报 ?另外,我从未见过有什么方法可以触发系统校准警报?

标签: swiftcore-location

解决方案


推荐阅读