IPhone Background Tasks

I am trying to implement location based updates in the background based on a timer. I know all about the various location update methods in iOS and have tried them, but they do not fit the needs. I need to check locations so often, even when they are inactive. I tried using timers, but they are not running in the background. This made me find this question. How do I get a background location update every n minutes in an iOS app? and it mentions use

UIApplication:beginBackgroundTaskWithExpirationHandler: 

My questions are: how do you use this method? I searched for Apple docs, but they recursively point to each other when working with background execution and location updates without examples.

I have this code based on some examples I found:

 - (void)applicationDidEnterBackground:(UIApplication *)application { locationUpdater=[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ [[UIApplication sharedApplication] endBackgroundTask:locationUpdater]; locationUpdater=UIBackgroundTaskInvalid; } ]; } 

And I added the "location" key in .plist for supported background modes

Does this only add that my application will not be killed for a certain amount of time so that I can maintain a timer? or where to add methods that should run in the background.

+4
source share
2 answers

If the background task runs for more than 10 minutes, your application will be terminated.

You really should use os location services to receive location change notifications. Why is this not enough? If the location does not change, then what is the point of retrieving it again and again, and after changing it you will be notified.

+1
source

For a conceptual understanding, see here .

For a detailed analysis of accuracy, you can visit this

you should start using startMonitoringSignificantLocationChanges . You can find sample code here.

0
source

All Articles