CMCalibratedMagneticField不更新 [英] CMCalibratedMagneticField doesn't update

查看:120
本文介绍了CMCalibratedMagneticField不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CMCalibratedMagneticField始终返回0.

CMAcceleration返回值,CMMagnetometerData也返回值. 只有CMCalibratedMagneticField不需要,我需要它,因为它是没有偏置的磁场.

CMAcceleration returns values, CMMagnetometerData returns values too. Only CMCalibratedMagneticField doesn't, I need it because it is the magneticfield without bias.

我正在iPhone 4S上进行测试.

I'm testing on 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)];

    }];

推荐答案

您是否检查了磁力计的准确性?我的猜测是您对motion.magneticField.accuracy的值将为-1(未校准).不幸的是,我不知道为什么会这样.即使磁力计工作正常,我在iPhone 4上也遇到了同样的问题.

Have you checked the magnetometer accuracy? My guess is your value for motion.magneticField.accuracy will be -1 (uncalibrated). Unfortunately I have no idea why this is. I'm getting the same thing with my iPhone 4, even though the magnetometer is working just fine.

我唯一能想到的是,手机在出厂前从未进行过校准,但这对我的4比对你的4S更有意义.校准场功能是iOS 5.0的新功能,该功能于2011年10月公开发布,而iPhone 4则是一年多以前发布的.但是您的手机是与5.0一起推出的,因此人们会认为所发布的硬件将与其所支持的软件功能相匹配.再次,只是猜测.抱歉,我不能再帮忙了.希望您会找到一个真正的答案.我只是打算自己校准磁力计.

The only thing I can figure is that the phone was never calibrated before leaving the factory, but that makes more sense for my 4 than for your 4S. The calibrated field feature was new for iOS 5.0 which was publicly released in October 2011, where as the iPhone 4 was released over a year before. But your phone came out right along with 5.0, so one would think that the hardware being released would match the software capability it was supporting. Again, just speculation. Sorry I can't be more help. Hopefully you'll find a real answer. I just plan on calibrating the magnetometer myself.

Freescale为此提供了免费的工具.该软件(和一些有用的文档)在此处提供.您可能必须创建一个免费帐户才能下载它,但我不记得了.

Freescale provides a free tool for doing this. The software (and some useful documentation) is available here. You might have to create a free account to download it, but I can't remember.

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

更新:我拥有一部iPhone 5,并且CMCalibratedMagneticField正常工作.

UPDATE: I got a hold of an iPhone 5 and the CMCalibratedMagneticField worked just fine.

这篇关于CMCalibratedMagneticField不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆