We can't use apple's Background Refresh, so we need another method to keepalive that isn't killed by the system. Here's my proposed solution. It's a hack, but for high-frequency checking on a server, I can't think of another way around it.
Use a locationmanager to keep the app active in the background. The manager is set to require only the weakest GPS signal, so it shouldn't add much drain on the battery (in fact the downloading of server data over poor cell reception is likely worse than GPS, in my experience).
The backgrounding option is opt-in on the settings page. I'm sure many don't want the battery drain of constantly hitting the server, so it is off by default.
To try to help with battery drain, server checks in the background are throttled to be less often than when the app is in the foreground. I've set this to 20 seconds vs 5.
While I was at it also cleaned up MapViewController to use CLLocationManager to get user location, not the mapview's current user location icon annotation.
Also updated the MapViewController to not try to update itself when the app is in the background. I'll now update when the app is brought to the foreground again.
Great idea, I'm gonna to test this system for a long time with "Instruments".
Thanks again for your hard work and your optimization, It's very appreciated !
We can't use apple's Background Refresh, so we need another method to keepalive that isn't killed by the system. Here's my proposed solution. It's a hack, but for high-frequency checking on a server, I can't think of another way around it.