-2

The iPhone app I'm writing has an option in the SETTING page: "ask for password when launching this app". (As a security measure.)

If the user types in the correct password... the app runs. If the user types in the wrong password... the app needs to immediately exit.

There isn't any kind of "immediately exit this app" in any framework (that I can find).

What is the app-store legal way to do this?

Alice
  • 141
  • 1
  • 5
  • possible duplicate of [Proper way to exit iPhone application?](http://stackoverflow.com/questions/355168/proper-way-to-exit-iphone-application) – ceejayoz Dec 08 '10 at 03:28
  • 1
    Why does it need to exit? Why not just keep the user at the Request Password screen until they give the correct password? – Bert F Dec 08 '10 at 03:32
  • 1
    The user gets 3 guesses... not infinite guesses. – Alice Dec 08 '10 at 04:05

3 Answers3

4

http://developer.apple.com/library/ios/#qa/qa2008/qa1561.html

There is no API provided for gracefully terminating an iPhone application. Under the iPhone OS, the user presses the Home button to close applications. Should your application have conditions in which it cannot provide its intended function, the recommended approach is to display an alert for the user that indicates the nature of the problem and possible actions the user could take - turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.

Just display a screen that says "The password you entered is invalid." Not sure why you wouldn't allow them to try again, though - I'd find being made to relaunch the app each time I make a typo quite frustrating.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
2

There is none. Applications are not supposed to exit. What you can do, however, is what an application I wrote that needed network access does: present a UIAlertView with no buttons so that the user is forced to quit the app (press the home screen button).

Just keep in mind that with iOS 4.0 and multitasking, you’ll have to give the user another opportunity to enter the password if the application is put into the background and then restarted.

Jeff Kelley
  • 19,021
  • 6
  • 70
  • 80
0

You can use

exit(0);

although not recommended as explained by others.

Ali
  • 829
  • 1
  • 8
  • 9
  • Do you know if that will make it through the Apple app-store approval process? – Alice Dec 08 '10 at 04:06
  • Since it looks like your app is crashing it probably won't pass the approval process. If you really need this, at least add a UIAlertView asking the user if they want to leave the app before closing it. – Ali Dec 10 '10 at 05:13