I'm developing an app that works in the background to get the user's location and send it to server using http requests. My first intention was to get the user's location every n minutes, but after alot of research and trial, i gave up since ios kills my background tasks after 3 minutes.
Then i tried working on MonitoringSignificantLocationChanges, but its inaccurate location updates due to cell tower usage ruins the purpose of my app.
A solution to any of the following is greatly appreciated:
- Getting user's location in background every n minutes infinitely.
- Getting user's location in background on SignificantLocationChanges with high accuracy(using gps)
- Any other background solution with high accuracy results.
Do the following:
in info.plist add the following
in code use LoctionManager to get location updates, (it will work in both foreground and background)
This is what works for me, I use CLLocationManagerDelegate, register for updates on didUpdateLocations and in app Delegate
I start updating location, the key for me, is when the app goes to background I switch to Significant Location Changes so the app doesn't drain the batter like this:
In didUpdateLocations, you can check
And start a task in the background to report the location for example
And start a task, I hope that helps.