Search code examples
iphoneiosshutdown

Can I proactively close my iOS app?


There are some rare data-corruption circumstances where rather than attempt a recovery in the same session, I'd like to perform some fixes and then shutdown the app so the next launch will be safe.

Short of hard crashing the app with something dumb like *(unsigned int *)0 = 0xDEADBEEF, I can't find an API in Cocoa that causes a graceful shutdown.

UPDATE: Found this documentation on the subject, that essentially confirms suspicion and points to exit as a last-ditch option:

http://developer.apple.com/iphone/library/qa/qa2008/qa1561.html


Solution

  • exit(0);
    

    Yep it works on the iPhone too.

    Alternatively,

    [[UIApplication sharedApplication] terminate];