Search code examples
iosterminatehome-button

Pause main execution before iOS app terminates


How can I make my app pause for a couple of seconds to invoke a message inside applicationDidEnterBackground when I hit the home button? For example:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [self.delegate aMessage];
    // Pause for a couple of seconds to give aMessage time to finish
    // Continue execution after 2 seconds
}

Solution

  • You can't, but you don't need to either. Your app gets to finish aMessage before it really goes into the background at which point you can't execute any code anymore.