开发者

Xcode - Adding network error alert code into my app?

开发者 https://www.devze.com 2023-02-06 19:27 出处:网络
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 {

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];
}

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 开发者_JAVA百科to link it to all uiwebviews, but it will only show up once if there is no connection.

Thanks for help in advance.


Check out Apple's Reachability sample code.


webView didFailLoadWithError: ---- to fire this everytime you come to webview write ur code in the viewWillAppear.... or try something like this in viewWillAppear ... [webView reload];

Njoy.... !

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号