CMDeviceMotion heading is -1.0

Viewed 695

There is a new heading property of CMDeviceMotion in iOS 11.

I'm trying to use it but find that it's always -1.0. It's supposed to hold degrees as a Double from 0.0 to 360.0.

My app targets iOS 11+, and I'm testing on a physical device (iPhone) running iOS 11.

let mmgr = CMMotionManager()
mmgr.showsDeviceMovementDisplay = true // for calibrating magnetometer, maybe not needed?
mmgr.deviceMotionUpdateInterval = 0.1
mmgr.startDeviceMotionUpdates(to: .main, withHandler: { (motionData: CMDeviceMotion?, error: Error?) in
    if let motion = motionData {
        print("heading:", motion.heading) // always -1.0
    }
})

I can get other properties just fine, such as motion.attitude.roll. Is there something I'm missing?

1 Answers
Related