我有一款健身应用程序,它可以接收位置更新,并且从iOS 4开始在后台运行良好。我只是注意到,当应用移动到iOS 10中的后台(切换应用程序或锁定设备)时,位置更新就停止了。我没有发现任何功能或后台权限更改的通知;有人知道发生了什么事吗?
我的位置设置非常基本:
if (!self.locationManager) {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.activityType = CLActivityTypeFitness;
self.locationManager.pausesLocationUpdatesAutomatically = TRUE;
}
// request permissions on iOS 8+
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}然后,此回调将接收更新:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
DLog(@"didUpdateToLocation");
}当应用程序处于前台时,一切都很好。一旦移动到后台,这些消息就会出现在控制台中:
/BuildRoot/Library/Caches/com.apple.xbs/Sources/ExternalAccessory/ExternalAccessory-353.22.1/EAAccessoryManager.m:__52-[EAAccessoryManager _checkForConnectedAccessories:]_block_invoke-785 ending background task然后更新停止。当我把这个应用带到前台时,他们又重新开始了。
我不直接使用EAAccessoryManager,只能猜测它是什么。我使用BluetoothLE框架从心率监视器接收数据,但是当我禁用此功能(停止实例化BluetoothLE对象)时,问题依然存在。
我的UIBackgroundModes设置为location、external-accessory和bluetooth-central,因为我还有鹅卵石手表连接。我试着添加bluetooth-peripheral,但这没有帮助。我也有NSLocationWhenInUseUsageDescription和NSBluetoothPeripheralUsageDescription集,它们都在工作。
发布于 2016-11-13 01:09:04
在CLLocationManager 9- allowsBackgroundUpdates中添加了一个新的属性.此属性默认为false,如果要在后台接收位置更新,则必须显式设置为true。
基于iOS 8 SDK构建的应用程序获得了grandfathered功能,即使没有设置此属性,也会继续接收后台更新。
https://stackoverflow.com/questions/40567272
复制相似问题