Can I proactively close my iOS app?

There are some rare data corruption situations in which, instead of trying to restore in the same session, I would like to make some corrections, and then turn off the application so that the next start is safe.

Finishing a hard crash of the application with something dumb like *(unsigned int *)0 = 0xDEADBEEF , I cannot find the API in Cocoa that causes a graceful shutdown.

UPDATE: found this documentation on this issue, which essentially confirms the suspicion and points to exit as an option with the last ditch:

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

+4
source share
3 answers
 exit(0); 

Yes, this also works on the iPhone.

As an alternative,

 [[UIApplication sharedApplication] terminate]; 
+8
source

When debugging a Debug assembly, I prefer something that crashes into a debugger, so I will not only know the reason, but also, if necessary, pull it out for more details. Sending a random message to any object other than nil is one of Objective-C's ways to do this.

 [ UIApplication foo: bar ]; 

For submission to the App Store -terminate, your application will definitely be rejected for using the (officially) undocumented API. And, reportedly, output (0) also does this, even if it is a documented OS call.

Prior to OS 4.0, you can always submit a Safari URL, which will cause your application to gracefully shut down. Not sure what to do in OS 4.0 and after that in the app store is legal.

0
source

This does not make any sense to me - no resource should be inaccessible for internal reset. Forced closing the application sucks for the user.

0
source

All Articles