0

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.

JPinios
  • 463
  • 1
  • 5
  • 10
  • i also want to achieve same behavior when app got kiled or say terminated. i want location updates in time interval or some changes in locations ... please help me if you have some solution for this – shaqir saiyed Aug 19 '17 at 07:26
  • Hi @shaqirsaiyed, you can try using startUpdatingLocation() and startMonitoringSignificantLocationChanges() methods. Don't forget to call stopUpdatingLocation() and stopMonitoringSignificantLocationChanges() when you don't need to track the position. You need to set pausesLocationUpdatesAutomatically=false and allowsBackgroundLocationUpdates = true to your CLLocationManager. This worked for me. Take care because you can drain the battery if you use intensively the GPS tracker. I hope you find it useful. Bye. – JPinios Aug 21 '17 at 20:38

0 Answers0