I have managed to get compass heading using CLLocationManager but because my app already uses CMMotionManager I would like to measure heading using exclusively CMMotionManager.
Like all Apple vague documentation, you have to guess how to use their APIs.
I have tried to use this to measure heading
[self.motionManager setMagnetometerUpdateInterval:1.0/30.0]; //30 Hz
[self.motionManager startMagnetometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMMagnetometerData *magnetometerData, NSError *error) {
CMMagneticField compass = magnetometerData.magneticField;
NSLog(@"x: %f y:%f z:%f", compass.x, compass.y, compass.z);
}];
the problem is that this block runs just a few seconds then stop running.
Is there any example of how to measure heading using CMMotionManager exclusively?
thanks.