我正在尝试从Apple 3 (WatchOS 5.1)获取核心运动数据,但是尽管DeviceMotion是可用的(isDeviceMotionAvailable属性是true),处理程序从未被触发。解析super.willActivate()后,我在控制台中得到以下消息
陀螺仪手动设置陀螺.中断.校准到800
我使用以下函数获取设备动态更新:
func startQueuedUpdates() {
if motion.isDeviceMotionAvailable {
self.motion.deviceMotionUpdateInterval = 1.0 / 100.0
self.motion.showsDeviceMovementDisplay = true
self.motion.startDeviceMotionUpdates(using: .xMagneticNorthZVertical, to: self.queue, withHandler:{
(data, error) in
// Make sure the data is valid before accessing it.
if let validData = data {
print(String(validData.userAcceleration.x))
}
})
}
}在我声明的InterfaceController中
let motion = CMMotionManager()
let queue : OperationQueue = OperationQueue.main以前有人见过这条消息并设法解决了吗?
注意:我检查了isGyroAvailable属性,它是false。
发布于 2019-06-18 11:56:25
这里的诀窍是将startDeviceMotionUpdates(using: CMAttitudeReferenceFrame参数与设备的功能相匹配。如果它没有磁强计,它就不能与磁北相关联,即使它有磁强计,它也不能与真正的北方相联系,除非它知道你在哪里(即有经纬度)。如果它没有遵从您选择的参数的功能,则将调用更新,但数据将为nil。
如果你用最小的.xArbitraryZVertical启动它,你会从加速度计得到更新,但是你不会得到一个有意义的标题,只是一个相对的标题,通过CMDeviceMotion.attitude属性。
if motion.isDeviceMotionAvailable {
print("Motion available")
print(motion.isGyroAvailable ? "Gyro available" : "Gyro NOT available")
print(motion.isAccelerometerAvailable ? "Accel available" : "Accel NOT available")
print(motion.isMagnetometerAvailable ? "Mag available" : "Mag NOT available")
motion.deviceMotionUpdateInterval = 1.0 / 60.0
motion.showsDeviceMovementDisplay = true
motion.startDeviceMotionUpdates(using: .xArbitraryZVertical) // *******
// Configure a timer to fetch the motion data.
self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
if let data = self.motion.deviceMotion {
print(data.attitude.yaw)
}
}
}https://stackoverflow.com/questions/54748841
复制相似问题