在Swift中制作Compass应用程序iOS

Ard*_*ner 4 ios swift swift2

我正在尝试将指南针模块集成到我的应用程序中.我使用了CoreLocationFramework,我加入CLLocationManagerDelegate了我的班级.我正在使用此代码初始化我的课程.

locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
Run Code Online (Sandbox Code Playgroud)

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

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

我添加NSLocationWhenInUseUsageDescription到我的Info.plist

提前致谢.

Rem*_*Hsu 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
Run Code Online (Sandbox Code Playgroud)