WatchOS 4 未收到后台 GPS 更新

background gps updates not received on WatchOS 4

发布这个问题和答案以便其他人可以找到它。

我们商店中有一个应用程序可以记录 activity 的路径。当我们将 WatchOS 更新到版本 4 时,当应用程序转换到后台时,我们的后台 gps 更新停止。

一些研究发现 link 在 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!!" 的行 这就是允许应用程序再次接收后台位置更新的原因。您还需要设置 link.

中提到的属性

Apps that want to receive location updates when suspended must include the UIBackgroundModes key (with the location value) in their app’s Info.plist file and set the value of this property to YES. The presence of the UIBackgroundModes key with the location value is required for background updates