我需要对 3 轴磁场、3 轴加速度和 3 轴旋转速率进行采样,所以我使用了 DeviceMotion,这是我的代码:
if manager.deviceMotionAvailable {
if manager.magnetometerAvailable {
manager.magnetometerUpdateInterval=0.01
manager.deviceMotionUpdateInterval = 0.01
manager.startDeviceMotionUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: {(data: CMDeviceMotion?, error: NSError?) -> Void in
if(standard_time) {
let data = [
"ax":data!.userAcceleration.x,"ay":data!.userAcceleration.y,"az":data!.userAcceleration.z,
"gax":data!.gravity.x,"gay":data!.gravity.y,"gaz":data!.gravity.z,
"gx":data!.rotationRate.x,"gy":data!.rotationRate.y,"gz":data!.rotationRate.z,
"mmx":data!.magneticField.field.x,"mmy":data!.magneticField.field.y,"mmz":data!.magneticField.field.z,
"roll":data!.attitude.roll, "pitch":data!.attitude.pitch, "yaw":data!.attitude.yaw]
}
)}
}
}
然而,无论我多么努力地移动我的 iPhone,我得到的 3 轴磁场值都固定为零。请你帮助我好吗 ???