1

Possible Duplicate:
Exit application in iOS 4.0

My client would like the app to shutdown when the user presses the 'Home' button. If the app icon is then touched again (either on the home screen or via double-tapping the home button and selecting the app), it would restart the app.

My initial attempt to call applicationWillTerminate from within applicationWillResignActive hasn't worked so I turn to you oh sage ones.

Is this possible and, if so, how?

Community
  • 1
  • 1
Stephen Morris
  • 289
  • 1
  • 5

4 Answers4

4

You don't need write any line of code. Just add UIApplicationExitsOnSuspend with BOOL value YES into 'Info.plist' file, and application will quit on pressing Home button.

Tomasz Wojtkowiak
  • 4,910
  • 1
  • 28
  • 35
2

Don't quit programatically.

I can't think of any reason why you would need your app to "start again". The whole point of multi tasking is that the app is saved in its current state and then returned to at a later time.

If you need to remove data, or reset variables or something similar then you can use applicationWillResignActive or similar methods to do so. You could even reset a navigation controller by calling popToRootViewController on it and such in this method, but don't force quit the application programatically. Apple won't like you, your users won't like you. There are better ways to do what you want to do.

Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224
  • _can't think of any reason why you would need your app to "start again"_ Unfortunately, there is a difference between what a developer wants and what a client wants. I have already made the argument to my client they should embrace the multi-tasking capabilities but alas, the client pays the bills. – Stephen Morris Jan 04 '12 at 14:00
  • Ah, a common issue in the life of a developer! :p – Thomas Clayson Jan 04 '12 at 14:40
0

Change the key UIApplicationExitsOnSuspend on your Info.plist to YES.

Iñigo Beitia
  • 6,303
  • 4
  • 40
  • 46
0

You don't have to write any code. Just include include the value YES for the key UIApplicationExitsOnSuspend in info.plist file selection "Application does not run in background" if you are editing the file as a property list.

Gabriel
  • 3,319
  • 1
  • 16
  • 21