CMCalibratedMagneticField
一直返回0
。
CMAcceleration
返回值,CMMagnetometerData
也返回值。只是CMCalibratedMagneticField
不需要,我需要它,因为它是没有偏差的磁场。
我在 iPhone 4S 上进行测试。
[MotionManager startDeviceMotionUpdatesToQueue:deviceQueue
withHandler:^(CMDeviceMotion *motion, NSError *error) {
CMCalibratedMagneticField f = motion.magneticField;
//CMMagneticField t = motion.;
//CMAcceleration s = motion.gravity; Works!
//_xlabelnew.text = [NSString stringWithFormat:@"%f", s.x];
_xlabelnew.text = [NSString stringWithFormat:@"%f", f.field.x];
_ylabelnew.text = [NSString stringWithFormat:@"%f", f.field.y];
_zlabelnew.text = [NSString stringWithFormat:@"%f", f.field.z];
//_totallabelnew.text = [NSString stringWithFormat:@"%f", sqrt(f.field.x*f.field.x + f.field.y*f.field.y + f.field.z*f.field.z)];
}];