1 year ago

#5428

test-img

Keselme

CLLocationManager startMonitoringSignificantLocationChanges doesn't work

I want my application to get location updates even if it's terminated I tried to sign up for location changes using SignificantLocationChanges but I seems that I'm not getting any updates.

In my AppDelegate.m I have the following setup:

@interface AppDelegate () <RCTBridgeDelegate, CLLocationManagerDelegate>

@property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
@property (nonatomic, strong) CLLocationManager* locationManager;
@property BOOL didShowLocationUpdateNotification;

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.locationManager = [[CLLocationManager alloc] init];
  [self.locationManager setDelegate:self];
  /// other setup
  [super application:application didFinishLaunchingWithOptions:launchOptions];
  return YES;
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{

 switch(status) {
  
case kCLAuthorizationStatusNotDetermined:
  NSLog(@"locationManagerDidChangeAuthorization - kCLAuthorizationStatusNotDetermined");
  break;
case kCLAuthorizationStatusRestricted:
  NSLog(@"locationManagerDidChangeAuthorization - kCLAuthorizationStatusRestricted");
  break;
case kCLAuthorizationStatusDenied:
  NSLog(@"locationManagerDidChangeAuthorization - kCLAuthorizationStatusDenied");
  break;
case kCLAuthorizationStatusAuthorizedAlways:
  [self.locationManager setAllowsBackgroundLocationUpdates:YES];
  [self.locationManager startUpdatingLocation];
  [self.locationManager startMonitoringSignificantLocationChanges];
  break;
case kCLAuthorizationStatusAuthorizedWhenInUse:
  NSLog(@"locationManagerDidChangeAuthorization - kCLAuthorizationStatusAuthorizedWhenInUse");
  break;
  }
}
    
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
    NSLog(@"didUpdateLocation");
  NSLog(@"Locations %@", locations);
}

I have the following Background Modes enabled:

enter image description here

I also have those keys in my info.plist:

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Your location is required to track your journeys. By selecting ALWAYS your journeys will record automatically.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your location is required to track your journeys.   </string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Your location is required to track your journeys. WARNING: Journeys will not automatically record with 'When In Use' selected</string>

And yet, after I terminate the app, it never wakes up again even though I changed my location drastically. What else am I mussing here? I'm testing it on iPhone 11 with iOS 15.

objective-c

ios-background-mode

0 Answers

Your Answer

Accepted video resources