Question

I have read a lot of posts and through the dev manuals and cannot find exactly how to setup the CMCalibratedMagneticField so that I am getting data out.

I am using:

[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.  

I know that it may be a stupid question as there is documentation but I am just not understanding the syntax of the setup. Any help would be much appreciated.

Was it helpful?

Solution

So the proper way to set it up is:

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

In my code I was indirectly trying to reference the value on the function side of this code and so was unable to get any direct values from it. But my function call now looks like:

-(void)showMagneticfield:(CMCalibratedMagneticField)magfield

and then calling the various fields by doing magfield.field.(axis)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top