[英]How to use CoreMotion in WatchKit?
I was quite dubious on this question's title phrasing, but I think that's the whole point as it is. 我对这个问题的标题措词非常怀疑,但我认为这就是重点。
I've been trying to just read the CoreMotion data on the WatchKit, but as it turns out, I can't get startDeviceMotionUpdatesToQueue
to work, my handler is never called. 我一直在想刚才读的WatchKit的CoreMotion数据,但事实证明,我不能让
startDeviceMotionUpdatesToQueue
工作,我的处理程序不会被调用。
I tried running in a custom background thread ( NSOperationQueue()
), still no luck. 我尝试在自定义后台线程(
NSOperationQueue()
)中运行,但还是没有运气。
I'm debugging on a real Apple Watch, not the simulator. 我在真正的Apple Watch上调试,而不是在模拟器上调试。
In my WKInterfaceController
: 在我的
WKInterfaceController
:
let manager = CMMotionManager()
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
let communicator = SessionDelegate()
manager.deviceMotionUpdateInterval = 1 / 60
manager.startDeviceMotionUpdatesToQueue(NSOperationQueue.mainQueue()) {
(motionerOp: CMDeviceMotion?, errorOp: NSError?) -> Void in
print("got into handler")
guard let motion = motionerOp else {
if let error = errorOp {
print(error.localizedDescription)
}
assertionFailure()
return
}
print("passed guard")
let roll = motion.attitude.roll
let pitch = motion.attitude.pitch
let yaw = motion.attitude.yaw
let attitudeToSend = ["roll": roll, "pitch": pitch, "yaw": yaw]
communicator.send(attitudeToSend)
}
print("normal stack")
}
the output is 输出是
normal stack
normal stack
(Yes, twice! I don't know why that either, but that is not the point, must be another thing I'm doing wrongly) (是的,两次!我也不知道为什么会这样,但这不是重点,一定是我做错了另一件事)
I'm posting this here 'cause I have no clue to where look into, this is freaking crazy. 我将其发布在这里,因为我不知道在哪里看,这简直太疯狂了。
startDeviceMotionUpdatesToQueue
中尚不提供Device Motion( startDeviceMotionUpdatesToQueue
)( deviceMotionAvailable
返回false),加速计可能可以帮助您startAccelerometerUpdatesToQueue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.