iOS位置管理器后台更新在iOS 10中停止

arl*_*dia 3 background-process core-location ios core-bluetooth

我有一个健身应用程序,可以接收位置更新,并且自iOS 4以来一直在后台工作正常.我只是注意到,当iOS中的应用程序移动到后台(切换应用程序或锁定设备)时,位置更新会停止.我没有发现任何功能或背景权限变更的通知; 有谁知道发生了什么?

我的位置设置非常基本:

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];
}
Run Code Online (Sandbox Code Playgroud)

然后这个回调接收更新:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    DLog(@"didUpdateToLocation");
}
Run Code Online (Sandbox Code Playgroud)

当应用程序处于前台时,一切都很好.一旦移动到后台,此消息就会出现在控制台中:

/BuildRoot/Library/Caches/com.apple.xbs/Sources/ExternalAccessory/ExternalAccessory-353.22.1/EAAccessoryManager.m:__52-[EAAccessoryManager _checkForConnectedAccessories:]_block_invoke-785 ending background task
Run Code Online (Sandbox Code Playgroud)

然后更新停止.当我将应用程序带到前台时,它们会再次恢复.

我没有直接使用EAAccessoryManager,只能猜测它是什么.我正在使用BluetoothLE框架从心率监视器接收数据,但是当我禁用此功能(停止实例化BluetoothLE对象)时,问题仍然存在.

我UIBackgroundModes分别设置location,external-accessory并且bluetooth-central因为我也有卵石手表连接.我尝试添加,bluetooth-peripheral但没有帮助.我也有,NSLocationWhenInUseUsageDescriptionNSBluetoothPeripheralUsageDescription设置,这些都在工作.

Pau*_*w11 6

CLLocationManager在iOS 9中添加了一个新属性- allowsBackgroundUpdates.如果要在后台接收位置更新,则此属性默认为false并且必须显式设置为true.

针对iOS 8 SDK构建的应用程序获得了grandfathered功能,并且即使不设置此属性也会继续接收后台更新.