1

I want my app to update location continuous in background. I have implemented below code.

 locationManager.pausesLocationUpdatesAutomatically =false
 self.locationManager = CLLocationManager()
 locationManager.requestWhenInUseAuthorization()
 locationManager.delegate = self
 locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
 locationManager.allowsBackgroundLocationUpdates=true
 locationManager.startMonitoringSignificantLocationChanges()
 self.locationManager.startUpdatingLocation()
  • This code manage in appdelegate didFinishLaunchingWithOptions()
Ashley Mills
  • 50,474
  • 16
  • 129
  • 160

1 Answers1

4

You need to call requestAlwaysAuthorization() to be able to receive location updates even when your app is running in the background. requestWhenInUseAuthorization() only gives you authorisation to receive location updates while your app is running in the foreground.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116