Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Possible Duplicate:
Exit application in iOS 4.0

I have a AlertView which displays some text and a "OK" button.

if user press ok button then app need to exit.

Is there any way to exit application when on click button.

share|improve this question
Never exit your application, else apple will reject your application. – Midhun MP Jan 15 at 12:18

marked as duplicate by trojanfoe, Sulthan, Janak Nirmal, dSquared, Tyler Crompton Jan 16 at 5:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

up vote 5 down vote accepted

exit(X), where X is a number (according to the doc) should work. But it is not recommended by Apple and won't be accepted by the AppStore. Why? Because of these guidelines (one of my app got rejected):

We found that your app includes a UI control for quitting the app. This is not in compliance with the iOS Human Interface Guidelines, as required by the App Store Review Guidelines.

Please refer to the attached screenshot/s for reference.

The iOS Human Interface Guidelines specify,

"Always Be Prepared to Stop iOS applications stop when people press the Home button to open a different application or use a device feature, such as the phone. In particular, people don’t tap an application close button or select Quit from a menu. To provide a good stopping experience, an iOS application should:

Save user data as soon as possible and as often as reasonable because an exit or terminate notification can arrive at any time.

Save the current state when stopping, at the finest level of detail possible so that people don’t lose their context when they start the application again. For example, if your app displays scrolling data, save the current scroll position."

> It would be appropriate to remove any mechanisms for quitting your app.

Plus, if you try to hide that function, it would be understood by the user as a crash.

share|improve this answer

You can use exit method to quit an ios app :

exit(0);

You should say same alert message and ask him to quit

Another way is by using [[NSThread mainThread] exit]

However you should not do this way

According to Apple, your app should not terminate on its own. Since the user did not hit the Home button, any return to the Home screen gives the user the impression that your app crashed. This is confusing, non-standard behavior and should be avoided.

share|improve this answer
You should not exit an iOS app yourself. – trojanfoe Jan 15 at 10:39
Please see my update.. – Anoop Vaidya Jan 15 at 10:40
Yes am showing a message like please upgrade and press ok to quit. – AVINASH KANNA Jan 15 at 10:41
if we use exit(0).is there any problem? – AVINASH KANNA Jan 15 at 10:42
Apple says NO to it. – Anoop Vaidya Jan 15 at 10:44
show 2 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.