2017-09-18 9 views
1

あるCMDeviceMotionの新しいheading propertyは、私はそれを使用するが、それは常に-1.0だことを見つけようとしているCMDeviceMotionの見出しは-1.0

iOSの11にあります。度はダブルで0.0から360.0まで保つことになっています。

マイアプリのターゲットのiOS 11+、と私は、このようなmotion.attitude.rollのような他の特性だけで罰金を得ることができます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 
    } 
}) 

を実行している物理デバイス(iPhone)でテストしています。私は行方不明のものがありますか?

答えて

1

問題は、私はCMAttitudeReferenceFrameオプションが含ま異なるメソッドシグネチャと運動のアップデートを開始するために必要なことです:

let mmgr = CMMotionManager() 
mmgr.deviceMotionUpdateInterval = 0.1 
mmgr.startDeviceMotionUpdates(using: .xMagneticNorthZVertical, to: .main, withHandler: { (motionData: CMDeviceMotion?, error: Error?) in 
    if let motion = motionData { 
     print("heading:", motion.heading) // works 
    } 
}) 

What's New in iOS 11ガイドでは、CMAttitudeReferenceFrameオプションにxArbitraryZVertical(デフォルト)またはxArbitraryCorrectedZVerticalを使用する場合と述べています、見出しは常に-1になります。

この便利なおしゃべりは、headingプロパティリファレンスに記載されていません。

+1

要件の良い要約、ありがとう。 – matt

+0

'startDeviceMotionUpdates(using:to:withHandler:)'を呼び出す必要はありませんので、答えで指定する必要はありません。必要なのは、単にモーションマネージャが用語「北」を含む参照フレームを持つ必要があることです。それを保証する他の方法があります。 – matt

関連する問題