ios - When we swipe to quit an application if applicationDidEnterBackground is not called 100% of the time how do we reliably save data? -


i asked earlier. think phrased question wrong. want save data app parse backend when application terminated. i.e. app swiped , killed list of apps. ios documents applicationdidenterbackground called , not applicationwillterminate work can done in method.

applicationwillterminate: apps not support background execution or linked against ios 3.x or earlier, method called when user quits app. apps support background execution, method not called when user quits app because app moves background in case. however, method may called in situations app running in background (not suspended) , system needs terminate reason.

however isn't 100% , testing applicationdidenterbackground isn't called every time quit app. how 1 save data when app terminated 100% guarantee saved?

this code saving when applicationdidenterbackground:

- (void)applicationdidenterbackground:(uiapplication *)application  {     bgtask = [application beginbackgroundtaskwithname:@"mytask" expirationhandler:^{         //end task         [application endbackgroundtask:bgtask];         bgtask = uibackgroundtaskinvalid;     }];     dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{         if([self getcontroller]){                             catsviewcontroller *catsviewcontroller = [self getcontroller];             if(catsviewcontroller.currentuser){                                     int count = (int)[myviewcontroller.currentuser.messages count];                 pfinstallation *currentinstallation = [pfinstallation currentinstallation];                 currentinstallation.badge = count;                 [currentinstallation saveinbackgroundwithblock:^(bool succeeded, nserror *error) {                     [application endbackgroundtask:bgtask];                     bgtask = uibackgroundtaskinvalid;                 }];                                 }                             else{                                     [application endbackgroundtask:bgtask];                 bgtask = uibackgroundtaskinvalid;             }         }                     else{                             [application endbackgroundtask:bgtask];             bgtask = uibackgroundtaskinvalid;         }     }); } 

would great pointers on this. thanks

you use applicationwillresignactive things that. has added bonus of being called when user opens notification center, too. called when user enters app switcher. if kills app, there nothing can it, because swiping app switcher send sigkill. if lucky, can background task before happens utilizing willresignactive.

i use applicationwillresignactive , applicationdidbecomeactive respectively, because both cover wider range of situations app not in foreground.

also read this answer here (and above)


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -