1

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
snksnk
  • 1,566
  • 4
  • 21
  • 46

3 Answers3

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.

Sam
  • 7,252
  • 16
  • 46
  • 65
Newbee
  • 3,231
  • 7
  • 42
  • 74
1

Write your actions in appDelegate's "applicationDidEnterBackground" method.

Sam
  • 7,252
  • 16
  • 46
  • 65
RKY
  • 266
  • 1
  • 7
  • 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