ios – 快速查找iPhone的指南针方向

我正在尝试制作一个类似指南针的应用程序,但是虽然有明显的差异,但它们并不重要.我需要知道的是:无论手机的方向如何,我怎样才能让iPhone给我罗盘方向(即北方0度)(即如果它平躺在桌子或肖像上,它会给出相同的读数.某人的手,如果指向相同的方式)

TL; DR如何围绕y轴获得iPhone的旋转,每秒左右更新一次.

解决方法

导入CoreLocation
class ViewController: UIViewController,CLLocationManagerDelegate {

    var lm:CLLocationManager!

    override func viewDidLoad() {
        super.viewDidLoad()

        lm = CLLocationManager()
        lm.delegate = self

        lm.startUpdatingheading()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func locationManager(manager: CLLocationManager!,didUpdateheading newheading: CLheading!) {
        println(newheading.magneticheading)
    }
}

您可以从https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLHeading_Class/获取更多信息

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...