How to quit iPhone app with an “intentional exception”?

蹲街弑〆低调 提交于 2020-01-17 11:28:08

问题


I know Apple frowns upon closing the app because the user might think it crashed.

So how do I make it quit intentionally with an exception that doesn't get caught when the user goes back to the home screen? Also, would this be rejected by the App Store?


回答1:


Please see the answer to this question:

Forcing a background application to terminate in iOS simulator

It will tell you how to setup your application to terminate instead of backgrounding when the user hits the home button.

If you don't want to do that, I recommend you should instead release resources when your delegate's applicationDidEnterBackground fires. I think that is your safest bet. More than one of us say what you're wanting to do is not ideal.




回答2:


I wrote this answer to another question. It an extract from the Apple Human interface guidelines and should help you understand why you shouldn't quit programatically.

You shouldn't force close an app as the standard way to terminate an application is to press the home button (or use the multitasking bar)

Don’t Quit Programmatically


Never quit an iOS application programmatically because people tend to interpret this as a crash. However, if external circumstances prevent your application from functioning as intended, you need to tell your users about the situation and explain what they can do about it. Depending on how severe the application malfunction is, you have two choices.

Display an attractive screen that describes the problem and suggests a correction. A screen provides feedback that reassures users that there’s nothing wrong with your application. It puts users in control, letting them decide whether they want to take corrective action and continue using your application or press the Home button and open a different application

If only some of your application's features are not working, display either a screen or an alert when people activate the feature. Display the alert only when people try to access the feature that isn’t functioning.

Source




回答3:


Apple will most likely reject it as a violation of the human interface guidelines, so it really doesn't matter how to do it.




回答4:


So how do I make it quit intentionally with an exception that doesn't get caught when the user goes back to the home screen?

You don't. If your app is "done," just go back to the initial state. Reset all your variables, release your view controllers, whatever. Pretend that the app actually did terminate, and that the user started it up again. You'll be happy, your users will be happy, and Apple will be happy.

An alternative, if your app truly can't continue for some reason, is to display a message that explains the situation to the user and tells them how to resolve the problem. Leave that message visible until the user leaves the app by pressing the Home button. This can be the only reasonable way to deal with situations where some resource such as network access is missing.

Also, would this be rejected by the App Store?

Nobody can say that for certain other than Apple, but I think the probability of rejection is high.



来源:https://stackoverflow.com/questions/8153174/how-to-quit-iphone-app-with-an-intentional-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!