Xcode - 将网络错误警报代码添加到我的应用程序中? [英] Xcode - Adding network error alert code into my app?

查看:64
本文介绍了Xcode - 将网络错误警报代码添加到我的应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想在我的iPhone应用程序中添加网络错误代码,这是我现在所做的事情:

Hi I want to add network error code into my iPhone app, heres what I have got up to now:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The page couldn't load, please check your internet connection and reopen the app." delegate:self
    cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alert show];
    [alert release];
}

我已将界面构建器中的webview与委托相关联。
它在模拟器上工作得很好,但是当我在iPhone上运行时,我意识到了一些事情。它只适用于第一次打开应用程序时没有互联网连接,如果您稍后打开应用程序没有互联网连接,它仍然在多任务栏,它不起作用。如果你在使用应用程序并尝试加载另一个页面时失去了互联网连接,那么它不起作用,这导致目前我只为1 uiwebview添加了这个代码,而如果错误确实显示,我有4个,否则它出现了4次。我需要找到一种方法将它链接到所有uiwebviews,但如果没有连接,它只会显示一次。

I have linked the webview in question in interface builder with delegate. It works on simulator quite well, but when I run it on my iPhone I realised a few things. It only works upon opening up the app the first time when theres no internet connection, if you open the app later with no internet connection and it's still in the multitasking bar it doesn't work. It doesn't work if you lose internet connection while using the app and try to load another page, and that leads on to that currently I have only added this code for 1 uiwebview, while I have 4 otherwise if the error does show up, it shows up 4 times. I need to work out a way to link it to all uiwebviews, but it will only show up once if there is no connection.

提前感谢您的帮助。

推荐答案

查看Apple的可达性示例代码。

Check out Apple's Reachability sample code.

这篇关于Xcode - 将网络错误警报代码添加到我的应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆