为什么magneticField.field的值固定为零?

时间:2016-07-31 03:06:07

标签: ios iphone swift magnetometer devicemotion

我需要采样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轴磁场的值都固定为零。你能帮我吗???

1 个答案:

答案 0 :(得分:1)

您似乎正在调用错误的方法来获取磁力计数据。

With cte as
(
    select 
        *,
        row_number() over (partition by id order by id) as rownum
    from 
        table 
)
select * 
from cte 
where rownum = 4