iphone - Perform an action after user dismiss the app on iOS -


i want perform action, ten seconds after app goes background , in condition user didn't app during time.

for doing so, using code:

 -(void)applicationdidenterbackground:(uiapplication *)application{        uibackgroundtaskidentifier __block bgtask = 0;       uiapplication  *app = [uiapplication sharedapplication];       bgtask = [app beginbackgroundtaskwithexpirationhandler:^{            [app endbackgroundtask:bgtask];            bgtask = uibackgroundtaskinvalid;       }];       dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{           [self checksession];       });  }    -(void)checksession{       sleep(10);       if([[uiapplication sharedapplication] applicationstate] != uiapplicationstateactive)  {           nslog(@"do action after 10 seconds");       }       else{          nslog(@"do nothing after 10 seconds");       }   } 

the problem if user terminate app while in background (by swipe , dismiss it) , before 10 seconds passed, action not performed, , i'll see log:

    <appdelegate: 0x15557890> ending background task 5 

any idea how perform action in case?

try use - (void)applicationwillterminate:(uiapplication *)application case user kills app before action performed


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -