0

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
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Hahnemann
  • 4,378
  • 6
  • 40
  • 64

1 Answers1

0

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.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
  • OK. I am asking because aMessage happens to be a socket call to node. When I hit the home button the socket goes away as it should. I would like to call aMessage and wait a couple of seconds before iOS destroys the socket. Sorry, I should have specified this. – Hahnemann Feb 06 '13 at 06:17
  • Well, you can't "delay" this method. As the name indicates, you are already in the background by the time this method is called. If your socket is still valid at the beginning of this method, my guess is that it is valid for the duration of the method. I work with sockets too, and I believe my socket stays around if I don't close it myself in `applicationDidEnterBackground:`. – Scott Berrevoets Feb 06 '13 at 06:24
  • We have a weird issue with our node server where this last aMessage must be broadcast to all connected clients. However, not all clients receive this message. My assumption was that the socket gets destroyed before the full message is broadcast, because every other message is broadcast with no issues. Maybe it's a problem with the node Socket library? – Hahnemann Feb 06 '13 at 06:45