2012-11-08 14 views
2

CMCalibratedMagneticField一直返回0CMCalibratedMagneticField不更新

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)]; 

    }]; 

回答

3

你檢查了磁力計的準確性嗎?我的猜測是你的motion.magneticField.accuracy值爲-1(未校準)。不幸的是,我不知道這是爲什麼。即使磁力計工作得很好,我的iPhone 4也能得到同樣的結果。

我唯一能想到的就是手機在出廠前從未校準過,但這對於我的4來說比4S更有意義。校準的字段功能是iOS 5.0的新功能,2011年10月公開發布,iPhone 4發佈一年前。但是你的手機與5.0一起出來,所以人們會認爲正在發佈的硬件會匹配它所支持的軟件功能。再一次,只是猜測。對不起,我無法提供更多幫助。希望你會找到一個真正的答案。我只是計劃自己校準磁強計。

飛思卡爾爲此提供了免費工具。該軟件(和一些有用的文檔)可在這裏找到。您可能必須創建一個免費帳戶才能下載它,但我不記得了。

http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=eCompass

更新:我得到了一個iPhone 5的保持和CMCalibratedMagneticField的工作就好了。

0
[MotionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryCorrectedZVertical toQueue: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)]; 

}];