使用Swift编写iOS指南针应用程序

4

我正在尝试将一个指南针模块集成到我的应用中。我使用了 CoreLocation 框架,并在我的类中添加了 CLLocationManagerDelegate 。我正在使用以下代码初始化我的类。

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)"
}

我已经在我的 Info.plist 文件中添加了 NSLocationWhenInUseUsageDescription。
提前感谢您。
1个回答

6
你错过了...
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

是的!非常感谢你。 - Arda Keskiner

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接