小编The*_*lya的帖子

运动经理不工作

我试图让设备运动(俯仰,滚动,偏航),但是我的函数handleDeviceMotionUpdate没有启动(我在iphone 5s上尝试它),这里是代码:

import UIKit
import CoreMotion

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()






    var motionManager = CMMotionManager()
    motionManager.startDeviceMotionUpdates()
    motionManager.deviceMotionUpdateInterval = 0.1


    motionManager.startDeviceMotionUpdatesToQueue(
        NSOperationQueue.currentQueue()!, withHandler: {
            (deviceMotion, error) -> Void in

            if(error == nil) {
                self.DeviceMotionUpdate(deviceMotion!)
            } else {
                print("error")
            }
    })

}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}

func DeviceMotionUpdate(deviceMotion:CMDeviceMotion) {
    print("function launched")
    var attitude = deviceMotion.attitude
    var roll = (attitude.roll)
    var pitch = (attitude.pitch)
    var yaw = (attitude.yaw)
    print("Roll: \(roll), Pitch: \(pitch), Yaw:  (yaw)")

}



}
Run Code Online (Sandbox Code Playgroud)

我没有在startDeviceMotionUpdatesToQueue中得到错误.我在motionManager.deviceMotionActive和motionManager.deviceMotionAvailable上都是如此

xcode cmmotionmanager swift ios9 swift2

5
推荐指数
1
解决办法
1316
查看次数

标签 统计

cmmotionmanager ×1

ios9 ×1

swift ×1

swift2 ×1

xcode ×1