1

我已经阅读了很多帖子和开发手册,但无法准确找到如何设置 CMCalibratedMagneticField 以便获取数据。

我在用:

[motionManager startDeviceMotionUpdatesUsingReferenceFrame: CMAttitudeReferenceFrameXMagneticNorthZVertical toQueue: [NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error){
    //This is where I don't know how to get the calibrated data but I am trying:
    CMCalibratedMagneticField *magfield = motion.magneticField.field;
    //then sending it to a function where I pull the x, y, and z values.  

我知道这可能是一个愚蠢的问题,因为有文档,但我只是不理解设置的语法。任何帮助将非常感激。

4

1 回答 1

0

所以正确的设置方法是:

CMCalibratedMagneticField magfield = motion.magneticField;
//send in the magfield to the function.

在我的代码中,我间接尝试引用此代码函数端的值,因此无法从中获取任何直接值。但我的函数调用现在看起来像:

-(void)showMagneticfield:(CMCalibratedMagneticField)magfield

然后通过执行 magfield.field.(axis) 调用各个字段

于 2014-01-23T19:03:52.700 回答