我有以下快速代码,我试着测试CMMotionManager是否正常工作,但每次我在模拟器上使用摇动手势时,结果并不是我所期望的,而是一个撤销绑定通知。
let manager = CMMotionManager()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if manager.deviceMotionAvailable {
manager.deviceMotionUpdateInterval = 0.02
manager.startDeviceMotionUpdatesToQueue(NSOperationQueue.mainQueue()) {
[weak self] (data: CMDeviceMotion?, error: NSError?) in
if data?.userAcceleration.x < -2.5 {
self?.resLabel.text = "Shaked"
}
}
}
}发布于 2016-05-27 04:04:31
模拟器不模拟任何运动。你必须使用物理设备来测试CMMotionManager中的任何东西。
https://stackoverflow.com/questions/37469114
复制相似问题