iOS*_*Dev 3 objective-c accelerometer ios core-motion
我正在使用以下代码获取加速度计数据(使用CoreMotion框架):
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
motionManager.accelerometerUpdateInterval = 1.0 / 60.0;
[motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
NSLog(@"ACCELEROMETER DATA = %@",accelerometerData);
}];
Run Code Online (Sandbox Code Playgroud)
当应用程序处于前台模式时,我正在接收日志,但是当它进入后台时,我只在应用程序中的音乐正在播放时才会收到日志.我已将以下内容添加到app info plist文件中:
- Required background modes
- App registers for location updates
- App plays audio or streams audio/video using AirPlay
Run Code Online (Sandbox Code Playgroud)
问题是:当音乐没有播放时,如何在后台接收加速度计更新?
您不仅可以使用加速度计从背景中获取数据,
就像你说的那样App registers for location updates,在前台启动位置管理器.
实现长时间运行的后台任务
对于需要执行更多执行时间的任务,您必须请求特定权限才能在后台运行它们而不会被挂起.在iOS中,只允许在后台运行特定的应用类型:
| 归档时间: |
|
| 查看次数: |
9420 次 |
| 最近记录: |