我正在尝试将指南针模块集成到我的应用程序中。我使用了 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/