Jam*_*ter 19
您不应强制关闭应用程序,因为终止应用程序的标准方法是按主页按钮(或使用多任务栏)
不要以编程方式退出
永远不要以编程方式退出iOS应用程序,因为人们倾向于将其解释为崩溃.但是,如果外部环境阻止您的应用程序按预期运行,您需要告知用户有关情况并解释他们可以采取的措施.根据应用程序故障的严重程度,您有两种选择.
显示描述问题的有吸引力的屏幕并建议更正.屏幕提供反馈,向用户保证应用程序没有任何问题.它使用户可以控制,让他们决定是否要采取纠正措施并继续使用您的应用程序或按Home键并打开其他应用程序
如果只有部分应用程序功能不起作用,则在人员激活该功能时显示屏幕或警报.仅当人们尝试访问无法运行的功能时才显示警报.
你的应用程序永远不会关闭自己 iOS没有退出应用程序的概念.您可以通知用户没有互联网连接并提供等待屏幕或其他显示他们的应用程序无用的内容,直到互联网连接可用,但您的应用程序应继续运行,直到操作系统决定关闭您.
根据八月份的ANS 这里
"On the iPhone there is no concept of quitting an app. The only action that should cause an app to quit is touching the Home button on the phone, and that's not something developers have access to.
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."
Run Code Online (Sandbox Code Playgroud)
但是,如果您仍想以编程方式退出应用程序,则有两个命令可以退出该应用程序.
1.exit(0)
2.[[NSThread mainThread] exit]
Run Code Online (Sandbox Code Playgroud)
不要关闭它,而是考虑通过弹出窗口向用户解释情况.
首先,从Apple下载Reachability.
将Reachability.h,.m,委托类添加到项目中.然后在.m类中导入Reachability
#import "Reachability.h"
Run Code Online (Sandbox Code Playgroud)
并且在viewWillAppear中或当您应该显示警报时:
//Connection check
Reachability *reach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [reach currentReachabilityStatus];
if (netStatus == NotReachable)
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"Explain the situation to the user" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
[alert release];
}
else {
//other actions.
}
Run Code Online (Sandbox Code Playgroud)
正如别人在我面前说的那样
| 归档时间: |
|
| 查看次数: |
3109 次 |
| 最近记录: |