I'm using CLLocationManager to get the coordinates from user, I need to get the location all the time (Uber driver style) in background and when the device is rebooted. I'm using allowsBackgroundLocationUpdates= true and pausesLocationUpdatesAutomatically=false to get locations in background and they are working ok, but when you reboot the phone sometimes CLLocationManager stop working.
I readed about startMonitoringSignificantLocationChanges method and (supposed) is the only way to continue getting locations after reboot device. But sometimes is working and sometimes not. I readed a lot of stackoverflows and doc, but I don't know what is happening.
Other failed approachs: a) I readed about Timers, but there is not the way because you can run it in foreground or only 3 min in background. b) In android you can send a message to wake up your app using a broadcast receiver (BOOT_COMPLETED), but in iOS it is not possible.
I thinks that the only possible way is using CLLocationManager but it has a rarely behavior when you reboot the iphone. Any idea?
This is my code:
private lazy var locationManager: CLLocationManager = {
let manager = CLLocationManager()
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.distanceFilter = 100
manager.pausesLocationUpdatesAutomatically=false
manager.allowsBackgroundLocationUpdates = true
manager.delegate = self
manager.requestAlwaysAuthorization()
return manager
}()
I'm testing with startUpdatingLocation and startMonitoringSignificantLocationChanges methods.
I'm testing in real device (iphone 6 plus - iOS 10.3) Thanks in advance.