我目前正在开发一个iOS应用程序,从CMMotionManager中提取磁强计数据。我创建了一个非常简单的测试应用程序,但即使该应用程序也无法在我的iPhone 5上运行。
- (void)viewDidLoad
{
[super viewDidLoad];
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
[motionManager setMagnetometerUpdateInterval:1.0/30.0f];
[motionManager startMagnetometerUpdatesToQueue:[[NSOperationQueue alloc] init]
withHandler:^(CMMagnetometerData *magnetometerData, NSError *error) {
NSLog(@"eek");
}];
}问题是处理程序从来没有被调用过。同样,调用[motionManager startMagnetometerUpdates],然后轮询magnetometerData也不起作用(它返回零)。在执行[motionManager isMagnetometerActive]时,结果总是false。
我被困在这里了,有什么想法吗?我不明白为什么代码不能工作。我一定要先请求访问指南针吗?CMMotionManager的文档除了提到我所做的事情之外,没有提到任何东西。
发布于 2013-12-04 23:43:08
我想你的motionManager会自动发布。添加实例变量或属性以保留运动管理器。
还请检查magnetometerAvailable是否返回是,否则可能您的设备不支持磁强计。
https://stackoverflow.com/questions/20388363
复制相似问题