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.
source share