在WatchOS上没有收到背景GPS更新4

问题描述:

用答案发布这个问题,让其他人可以找到它。在WatchOS上没有收到背景GPS更新4

我们在商店有一个应用程序,记录一个活动的路径。当我们将WatchOS更新到版本4时,当应用程序转换到后台时,我们的背景GPS更新停止。

一些研究发现在Apple's Developer site上的此链接显示我们需要在位置管理器中设置一个新属性。

self.locationManager = [[CLLocationManager alloc] init]; 
self.locationManager.delegate = self; 
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; 
if (@available(watchOS 4.0, *)) { 
    self.locationManager.activityType = CLActivityTypeOther; 
    self.locationManager.allowsBackgroundLocationUpdates = YES; // NEW!! 
} 

[self.locationManager startUpdatingLocation]; 

看到标有“NEW !!”的行这就是允许应用程序再次接收后台位置更新的原因。您还需要按照链接中所述设置属性。希望暂停时必须包括 ,在其应用的 Info.plist文件中UIBackgroundModes键(与位置值),该属性的值设置为YES接收位置更新

应用。具有位置值的UIBackgroundModes密钥的存在为 为后台更新所需的