Reputation: 18827
I want to develop an iPhone app that retrieves the user location constantly. Even if the user reboots the device or kills the app. I have set the location background mode on the .plist
file and create the location manager with the following options:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
locationManager = CLLocationManager()
locationManager!.requestAlwaysAuthorization()
locationManager!.distanceFilter = 100
locationManager!.activityType = .Fitness
locationManager!.desiredAccuracy = kCLLocationAccuracyHundredMeters
locationManager!.pausesLocationUpdatesAutomatically = true
locationManager!.delegate = self
locationManager!.startUpdatingLocation()
return true
}
I receive location updates, but if I reboot the device the location updates stop and wont start again until you start the app again.
How can I restart the location updates after a reboot?
Upvotes: 0
Views: 1131
Reputation: 7876
If you are building a non-jailbroken app, you can't.
You have to understand that iOS apps are very strictly sandboxed. You app can't decide to re-launch itself or start a background service when killed or already in the background.
You will have to reconsider this feature.
EDIT:
According to this answer from danielbeard, if your app was monitoring significant location changes with startMonitoringSignificantLocationChanges
, iOS will wake it up even after a reboot. But if the user manually killed your app, iOS will not restart it.
Upvotes: 1