ios - 在 Swift 中制作一个指南针应用程序 iOS

标签 ios swift swift2

我正在尝试将指南针模块集成到我的应用程序中。我使用了 CoreLocation 框架,并将 CLLocationManagerDelegate 添加到我的类中。我正在用这段代码初始化我的类(class)。

locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()

然后我调用下面的函数,但我没有得到任何输出。

func locationManager(manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
    let h = newHeading.magneticHeading
    let k = newHeading.trueHeading
    print(h)
    print(k)
    label.text = "\(h)"
}

我将 NSLocationWhenInUseUsageDescription 添加到我的 Info.plist

提前致谢。

最佳答案

你错过了..

locationManager.startUpdatingHeading

//Starts the generation of updates that report the user’s current heading.
- startUpdatingHeading

//Starts the generation of updates that report the user’s current location.
- startUpdatingLocation

关于ios - 在 Swift 中制作一个指南针应用程序 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31156836/

相关文章:

ios - 如何在 View 中的特定点添加 subview

javascript - 使用 Jquery 在 iPad 中双击

ios - 如何在 View 上创建扩展以在长按手势上显示警报 - SwiftUI

ios - swift 弹出本地通知,没有角标(Badge)

ios - AlamofireObjectMapper/ObjectMapper是否支持struct类型映射

ios - Facebook 注销按钮(iOS SDK)在注销时适当的 segue

ios - xcode-将登录屏幕输入链接到网站输入

ios - 进入viewController后如何加载数据?

ios - 等待 X 秒或等待用户输入

Swift:使用 as/as 进行转换有什么区别?/as!关键字和 C 风格的转换?