我正在开发一个完全基于Web数据的iPhone应用程序.
如果它没有连接到互联网,该应用程序是没有用的.
所以,我想在找不到连接时终止应用程序.
NSURL *tmpURl=[NSURL URLWithString:[NSString stringWithFormat:@"%@search.php",[iGolfAppDelegate getServerPath]]];
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:tmpURl];
con=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(con){
myWebData=[[NSMutableData data] retain];
} else {
//Yes I will provide two buttons on alertview "retry" & "close", & when user
//taps on "close" => application should terminate.
// i will send alertview & when user taps on button close then
// what to write for terminating application?
// Ok Ok. Don't terminate. User will terminate.
// user is owner of iPhone
// let him choose what to do
// wait till wifi connects
}
Run Code Online (Sandbox Code Playgroud)
问题是如何终止申请?
是exit(0)只用于终止应用程序的选项,或是否有任何其他选项可用?
Nik*_*uhe 17
Apple对此话题绝对清楚:
没有为优雅地终止iPhone应用程序提供API.在iPhone OS下,用户按Home键关闭应用程序.如果您的应用程序具有无法提供其预期功能的条件,建议的方法是为用户显示警告,指示问题的性质以及用户可能采取的操作 - 打开WiFi,启用位置服务等.允许用户自行决定终止申请.
Ste*_*ker 10
您可能会考虑通知用户他们在没有活动网络连接的情况下无法使用您的应用程序.直接终止应用程序似乎是一种非常不友好的方式来做到这一点; 用户只会看到应用程序"消失".
我见过的每个表现良好的应用程序至少会在终止之前发出通知.
我建议你重新考虑3个原因
如果(无论出于何种原因)你想要这样做,你可以使用.
exit(0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8264 次 |
| 最近记录: |