Search code examples
watchkitwatchos-4

background gps updates not received on WatchOS 4


Posting this question with an answer so other's can find it.

We have an app on the store which records an activity's path. When we updated the WatchOS to version 4, our background gps updates stopped when the app transitioned into the background.


Solution

  • Some research found this link on Apple's Developer site that shows we need to set a new property in the location manager.

    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];
    

    See the line marked "NEW!!" That's what allowed the app to receive background location updates again. You also need to have the properties set as mentioned in the 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