1

複数のボタンを備えた標準のView Controllerを備えたアプリがあります。各ボタンは、固有の UIWebView を持つ個別のビュー コントローラーにリンクします。各 UIWebView には didFailLoadWithError が実装されており、正常に動作しているようです。Wi-Fi をオフにして、メイン ビュー コントローラー ページから UIWebView を読み込もうとすると、didFailLoadWithError からエラー メッセージが正しく表示されます。wifiをオンにしてUIWebViewをロードすると、正常に動作します-エラーはありません。ただし、その UIWebView ページ内のリンクをクリックすると、 didFailLoadWithError エラーが再び発生します。さらに興味深いことに、エラー メッセージをクリアしても、クリックしたばかりのリンクから新しいページが読み込まれるので、接続が良好であることがわかります。これが私の実装です...

@synthesize webView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network Alert"    message:@"No Internet Connection - Please Check Your Network Settings and Try Again" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alert show];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:     @"http://www.site.com/index.html"]]];
    [webView addSubview:activity];
    timer=[NSTimer scheduledTimerWithTimeInterval:(1.0/2.0)
        target:self selector:@selector(loading) userInfo:nil repeats:YES];
           }

- (void)loading {
    if (!webView.loading)
        [activity stopAnimating];
        else
            [activity startAnimating];
}
4

1 に答える 1

2

私はちょうどこの問題を抱えていました。Web ビュー内のリンクをクリックすると、ページの読み込み中にエラーが発生します-999。これは に変換されNSURLErrorCancelledます。

詳細については、次のリンクを参照してください。セクションに移動しURL Loading System Error Codesます。https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html

私のコードでは、-webView:didFailLoadWithError:呼び出し時にインターネット接続が失われたことを示す警告ビューをポップアップするように指示していました。そのコードをエラー オブジェクトの条件にラップしました。例を示します。

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    if ([error code] == NSURLErrorNotConnectedToInternet || [error code] == NSURLErrorNetworkConnectionLost) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Check internet connection." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];
    }
}
于 2014-01-22T06:15:53.490 に答える