Reputation: 153
I have the problem that my app wont update the users location when the app entere in background mode.
I've read a lot about and have already set in app properties the flan "location" for UIBackgroundModes.
Even after that, my app drops the location manager in background and stops updating the users location.
Am i missing something ?
Upvotes: 1
Views: 4050
Reputation: 446
I ran into the same issue and basically you have to set the pausesLocationUpdatesAutomatically flag to "NO" on your CLLocationManager.
Upvotes: 1
Reputation: 42139
In iOS5 be sure to use locationManager:didUpdateToLocation:fromLocation:
. It is the method that keeps your app requesting location services even in the background. In iOS6 you should use locationManager:didUpdateLocations:
as locationManager:didUpdateToLocation:fromLocation:
is deprecated in iOS6.
In iOS6 make sure you add the following or else location services will be turned of when the system thinks you are not using it:
if ([self.locationManager respondsToSelector:@selector(pausesLocationUpdatesAutomatically)]) {
self.locationManager.pausesLocationUpdatesAutomatically = NO;
}
Upvotes: 2
Reputation: 28727
No change in position means no location, means no event, and no action.
If iphone moves and standard location mode is set (startUpdatingLocation
)
The you usually get one GPS fix per second. (desiredAccuracy = kCLLocationAccuracyBest
or kCLLocationAccuracyBestForNavigation
)
If location service was started by startMonitoringSignificantLocationChanges
then you will only get location determined by cell tower changes.
Further since ios6 there is a defered mode, such that your application will not get position changes while in background, but later all locations at once. ( I have no personal experiecne with that mode). But this also is to be considered in ios6 and higher
From CLLocationManager description
In iOS 6 and later, you can defer the delivery of location data when your app is in the background. It is recommended that you use this feature in situations where your app could process the data later without any problems. For example, an app that tracks the user’s location on a hiking trail could defer updates until the user hikes a certain distance and then process the points all at once. Deferring updates helps save power by allowing your app to remain asleep for longer periods of time.
Upvotes: 1
Reputation: 1754
Using apps in background mode is strongly restricted in iOS.
Generally, when the correct properties are set in UIBackgroundModes, your app will be called on each location update. By setting the required accuracy low (e.g. kCLLocationAccuracyBest
), your app will be started even on slight updates of the location.
However after a certain time and the app was not brought back into foreground, the app will be killed entirely and location services will be switched off (the latter only from iOS 6 on). Being unable to make the app continuously getting updates from iOS in the background made me give up my project.
Upvotes: 1