如何访问磁力计数据



遵循文档,这是我尝试访问磁力计数据的尝试。不用说,它行不通。

我已经使用完全相同的方法获得了陀螺仪和加速度计数据,但是由于某种原因,我使用此轴将所有零都在每个轴上。

 motionManager = [[CMMotionManager alloc] init];

[motionManager startDeviceMotionUpdates];
[motionManager startMagnetometerUpdatesToQueue:
 [NSOperationQueue currentQueue] withHandler:^(CMMagnetometerData *magnetometerData, NSError *error) {
     double x = motionManager.deviceMotion.magneticField.field.x;
     double y = motionManager.deviceMotion.magneticField.field.y;
     double z = motionManager.deviceMotion.magneticField.field.z;
     self.magnetometerDataLabel.text = [NSString stringWithFormat:@"{%8.4f, %8.4f, %8.4f}", x, y, z];
 }];
motionManager.magnetometerUpdateInterval = 1.0 / 60.0;

我缺少什么?

这有效:

[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryCorrectedZVertical toQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
    double x = motionManager.deviceMotion.magneticField.field.x;
    double y = motionManager.deviceMotion.magneticField.field.y;
    double z = motionManager.deviceMotion.magneticField.field.z;
    self.magnetometerDataLabel.text = [NSString stringWithFormat:@"{%8.4f, %8.4f, %8.4f}", x, y, z];
}];

相关内容

  • 没有找到相关文章

最新更新