I've recently upgraded my iOS devices to use iOS 7. One of the apps that we're developing uses background location services to track device location and all of our testers have reported that the app no longer appears to track in the background under iOS 7.
We have verified that backgrounding for the app is enabled in the settings on the device and the previous build worked flawlessly under iOS 6. Even if the device were cycled, the app would restart after a location update.
Is there something else that needs to be done to make this work under iOS 7?
If you look at WWDC 2013 Session video #204 - What's new with multitasking pdf, page number 15 clearly mentions that apps wont launch in the background if user kills it from the app switcher. Please see the image,
Here is the solution that I used to get continuous location from iOS 7 devices no matter it is in foreground or background.
You may find the full solution and explanation from blog and also github:-
Background Location Update Programming for iOS 7 and 8
Github Project: Background Location Update Programming for iOS 7 and 8
Methods and Explanation:-
I restart the location manager every 1 minute in function didUpdateLocations
I allow the location manager to get the locations from the device for 10 seconds before shut it down (to save battery).
Partial Code Below:-
Update on May 2014: I got a few requests for adding sample codes on sending the location to server for a certain time interval. I have added the sample codes and also combined a fix for BackgroundTaskManager to solve a glitch for background running over an extended period of time. If you have any questions, you are welcomed to join us for a discussion here: Background Location Update Programming for iOS 7 with Location Update to Server Discussion
Update on January 2015: If you want to get the location update even when the app is suspended, please see: Get Location Updates for iOS App Even when Suspended
Is the icon on the status bar turned on? It's a strange behaviour I had too. Check my question: startMonitoringSignificantLocationChanges but after some time didUpdateLocations is not called anymore
I discovered that the significant location changes was on but simply stopping and restarting the service (for significant changes) was not firing new locations.
One of my iOS app needs to send location update to server at regular intervals and following approach worked for us....
Starting in iOS 7:
So, DO NOT STOP the location updates anytime...Instead, prefer to use the necessary accuracy (fine location vs coarse location). Coarse location does not consume much battery...so this solution solves your problem.
After much searching online, found a link which provide a viable solution for iOS 7. The solution is as follows:
And make sure you add the following to your application’s Info.plist “location” to the UIBackgroundModes key “location-services” and “gps” to the UIRequiredDeviceCapabilities key
Credits: http://gooddevbaddev.wordpress.com/2013/10/22/ios-7-running-location-based-apps-in-the-background/
You must set
pausesLocationUpdatesAutomatically
property ofCLLocationManager
class to false to disable system from pausing the location updates.I think they made an optimization (probably using motion sensors), to detect "relatively" stationary positioning of the phone and they stop the location updates. This is only a speculation, but my tests currently show:
The data I log shows the geo-updates stop coming after ~ 15m and 30s. With that all other background processing you do is also terminated.
My device is iPhone 5 with iOS 7.
I am 95% sure, this wasn't the case on iOS 6/6.1. Where getting geo updates with 100m accuracy used to give you pretty much continuous running in background.
Update
If you restart the location manager every 8 minutes, it should run continuously.
Update #2
I haven't tested this in latest, but this is how I restarted it when I wrote the post. I hope this is helpful.