snksnk
snksnk

Reputation: 1595

Do action upon exit of ios app

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.

Upvotes: 1

Views: 829

Answers (3)

RKY
RKY

Reputation: 266

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

Upvotes: 1

Newbee
Newbee

Reputation: 3301

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.

Upvotes: 2

Andrei Filip
Andrei Filip

Reputation: 1153

Use the method,

- (void)applicationDidEnterBackground:(UIApplication *)application

In your application's delegate.

Upvotes: 2

Related Questions