IOS – background task and precise geolocation

When trying to work in background with IOS, things get tricky particularly when it requires a good precision update (when the significant update stuff is not enough).

first thing to do : start a background task :

- (void)applicationDidEnterBackground:(UIApplication *)application


    bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{

        // Clean up any unfinished task business by marking where you

        // stopped or ending the task outright.

        [application endBackgroundTask:bgTask];

        bgTask = UIBackgroundTaskInvalid;



    // Start the long-running task and return immediately.

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{


        // Do the work associated with the task, preferably in chunks.


        [application endBackgroundTask:bgTask];

        bgTask = UIBackgroundTaskInvalid;



Extracted from apple dev center:

while the task is running the didUpdateLocation event is correctly handle by the application.

you have only 180 seconds to finish the task before being killed by the OS. use the backgroundTimeRemaining to see how much time is left. Make sure you have finite task and you have the correct background mode setup to avoid being killed before.

Auteur/autrice : Chrystophe Vergnaud

Prendre du recul pour identifier les réels besoins et faire un choix technologique en fonction de ces besoins.

Laisser un commentaire