我最近升级了我的xcode。 我目前正在使用 9.2 我正在使用CMMotionManger,此错误显示在新版本中。我尝试解决它,但找不到解决方案。
func startCameraTracking() {
motionManager.deviceMotionUpdateInterval = 1.0 / 60.0
motionManager.startDeviceMotionUpdatesToQueue(OperationQueue.main) {
[weak self](data: CMDeviceMotion?, error: NSError?) in
guard let data = data else { return }
let attitude: CMAttitude = data.attitude
self?.cameraNode.eulerAngles = SCNVector3Make(Float(attitude.roll + M_PI/2.0), -Float(attitude.yaw), -Float(attitude.pitch))
}
}
正如Michael所建议的,你最好检查一下最新的参考资料:
(startDeviceMotionUpdatesToQueue(_: withHandler:)
重命名为startDeviceMotionUpdates(to:withHandler:)
.(
startDeviceMotionUpdates(to:withHandler:)
声明
func startDeviceMotionUpdates(to queue: OperationQueue, withHandler handler: @escaping CMDeviceMotionHandler)
CMDeviceMotionHandler
声明
typealias CMDeviceMotionHandler = (CMDeviceMotion?, Error?) -> Void
对于startDeviceMotionUpdates(to:withHandler:)
的第二个参数,你需要传递一个闭包,取CMDeviceMotion?
和Error?
,而不是NSError?
:
func startCameraTracking() {
motionManager.deviceMotionUpdateInterval = 1.0 / 60.0
motionManager.startDeviceMotionUpdates(to: OperationQueue.main) {
[weak self](data: CMDeviceMotion?, error: Error?) in
guard let data = data else { return }
let attitude: CMAttitude = data.attitude
self?.cameraNode.eulerAngles = SCNVector3Make(Float(attitude.roll + .pi/2.0), -Float(attitude.yaw), -Float(attitude.pitch))
}
}