Reputation: 11961
I have a button that will close my app.
I am using exit(0);
but I dont like the way it closes my app, its like when an app crashes and the app closes kinda close. I am looking for away to terminate when the user pushes this button. Any suggestions?
Thanks
I have tried the following:
[[NSThread mainThread] exit];
but got this error:
No visible @interface for 'NSThread' declares the selector 'exit'
Upvotes: 3
Views: 1387
Reputation: 70743
The only approved method to exit an app it to set the (Apple documented) exits-on-suspend app plist key, and then have the app send a URL to launch another app (such as Safari). iOS will then cleanly terminate your app instead of backgrounding it.
Upvotes: 2
Reputation: 15512
The is no proper way to do that. You should use exit(0);
to go from application. But for increasing of the user experience just add some few lines :
//home button press programmatically
UIApplication *app = [UIApplication sharedApplication];
[app performSelector:@selector(suspend)];
//wait 2 seconds while app is going background
[NSThread sleepForTimeInterval:2.0];
//exit app when app is in background
exit(0);
Upvotes: 2