This question has been asked before CMCalibratedMagneticField doesn't update but it wasn't really answered. I am very lost on this one.
I'm using a simple formulation, but field.field.x, y, z are always zero.
if (motionManager.deviceMotionAvailable)
{
[motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:
^(CMDeviceMotion *motionData, NSError *error) {
CMCalibratedMagneticField field = motionData.magneticField;
NSLog(@"x: %f y:%f z:%f", field.field.x
, field.field.y
, field.field.z);
}];
}
Sample output is
2013-07-14 22:18:27.865 TestApp[6678:907] x: 0.000000 y:0.000000 z:0.000000
2013-07-14 22:18:27.869 TestApp[6678:907] x: 0.000000 y:0.000000 z:0.000000
2013-07-14 22:18:27.879 TestApp[6678:907] x: 0.000000 y:0.000000 z:0.000000
I am pretty certain the issue is not the phone as the preceding answer suggested: I am coding for a fairly modern 4S. I have the CoreMotion, CoreLocation, and CoreData frameworks in place -- maybe there is a header file I don't know about that I need to import in the implementation? currently I only seem to need
#import <tgmath.h>
but that is for other stuff.
Any help would be appreciated!
Tim Redfield