How can I assign actions on iOS when a user presses the home button (exit)? I want this for an app where uses user a login feature and I want, upon exit, the user to log out. I dont want to use a button for this.
Asked
Active
Viewed 816 times
3 Answers
2
Use the method,
- (void)applicationDidEnterBackground:(UIApplication *)application
In your application's delegate.

Sam
- 7,252
- 16
- 46
- 65

Andrei Filip
- 1,145
- 15
- 33
2
You can't exit an application programmatically, you can use exit(1)
, however it's not a good practice, chances are there for your apps to get rejected from Apple.
applicationDidEnterBackground
will be called for home button press. Try to handle everything here.
1
Write your actions in appDelegate
's "applicationDidEnterBackground
" method.
-
3@Andrei Because applicationWillResignActive get called every time app get some specific interruption line phone call, sms. If You want to schedule notification when user press home button and in this case applicationDidEnterBackground is the appropriate place to do this. – RKY Sep 04 '12 at 11:29