2016-10-18 23 views
5

在iPhone 6與iOS 10.0.2,我得到一個錯誤與下面的代碼:CoreLocation:CPAS數據響應invaild

class ViewController: UIViewController { 

    @IBOutlet weak var startStop: UIButton! 

    var isRunning = false 

    let manager: CMMotionManager = { 
     let manager = CMMotionManager() 
     manager.deviceMotionUpdateInterval = 1/100 
     return manager 
    }() 

    @IBAction func handleStartStop(_ sender: AnyObject) { 
     if isRunning { 
      stopMotionUpdates() 
      startStop.setTitle("Start", for: .normal) 
     } else { 
      startMotionUpdates() 
      startStop.setTitle("Stop", for: .normal) 
     } 
     isRunning = !isRunning 
    } 

    func startMotionUpdates() { 
     manager.startDeviceMotionUpdates(using: .xTrueNorthZVertical, to: .main) { (data, error) in 
      print("Roll: \(data!.attitude.roll), Pitch: \(data!.attitude.pitch), Yaw: \(data!.attitude.yaw)") 
     } 
    } 

    func stopMotionUpdates() { 
     manager.stopDeviceMotionUpdates() 
    } 

} 

輸出:

2016-10-19 07:45:13.865847 CoreMotionTest[562:350766] CoreLocation: CPAS data response was invaild. 
Roll: -0.0135864792263794, Pitch: 0.00864587532420694, Yaw: 6.47493275587377e-05 
Roll: -0.0135915108585011, Pitch: 0.00865699352311076, Yaw: 7.09129926643357e-05 
Roll: -0.0135963930210582, Pitch: 0.00867386848019366, Yaw: 8.84424471509634e-05 
Roll: -0.0136066048134502, Pitch: 0.00868011794373523, Yaw: 0.000105925819254466 
Roll: -0.0136114190872102, Pitch: 0.00867577431915433, Yaw: 0.000117932969705823 
Roll: -0.0135948730328641, Pitch: 0.00867657982050841, Yaw: 0.00012968687069689 
Roll: -0.0135732480451522, Pitch: 0.00867729811777266, Yaw: 0.000152007924023406 
Roll: -0.0135619969691634, Pitch: 0.00868342424259059, Yaw: 0.000163872505991956 
Roll: -0.013304139897602, Pitch: 0.00874500976978164, Yaw: 0.000179014630004322 
Roll: -0.0133409772363028, Pitch: 0.00887204866716325, Yaw: 0.00018600114405152 
Roll: -0.0130968013066843, Pitch: 0.00890815168076916, Yaw: 0.000201127439543817 
Roll: -0.0129980717242318, Pitch: 0.00898203106432451, Yaw: 0.00022290167061286 
Roll: -0.013058759809209, Pitch: 0.008972000868579, Yaw: 0.000240753238817741 
Roll: -0.0130954579972119, Pitch: 0.0089717830946822, Yaw: 0.000258417382421598 

任何想法意即?

回答

1

它與使用指南針的請求有關。 xMagneticNorthZVertical導致它而xArbitraryZVertical不導致。

+0

非常感謝! – doovers

+0

我用startMagnetometerUpdates得到它。還沒有弄清楚爲什麼。 –

+0

如果我要求使用指南針.xMagneticNorthZVertical,我該怎麼辦? – OtakuFitness