当应用程序在后台运行/设备处于睡眠模式时,我需要加速器更新.一些应用程序这样做,我无法使其工作.为此,我在appdelegate和我调用的applicationDidEnterBackground中有一个CoreMotion属性
-(void) startAccelerationUpdates
{
self.motionManager.deviceMotionUpdateInterval = 0.01;
[self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue]
withHandler:^(CMDeviceMotion *motion, NSError *error){
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"acceleration x %f", motion.userAcceleration.x);
NSLog(@"acceleration y %f", motion.userAcceleration.y);
NSLog(@"acceleration z %f", motion.userAcceleration.z);
}
);
}
];
}
Run Code Online (Sandbox Code Playgroud)
在app plist中,我将所需的后台模式放到App寄存器中以进行位置更新.当我将设备置于睡眠模式或后台时,日志中不会显示任何更新.当应用程序处于活动状态时,coremotion会启动loggin.有人给我一个暗示吗?谢谢.