NSError

参考文档 Using and Creating Error Objects


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

    NSString *errorMsg;

    if ([[error domain] isEqualToString:NSURLErrorDomain]) {

        switch ([error code]) {

            case NSURLErrorCannotFindHost:

                errorMsg = NSLocalizedString(@"Cannot find specified host. Retype URL.", nil);

                break;

            case NSURLErrorCannotConnectToHost:

                errorMsg = NSLocalizedString(@"Cannot connect to specified host. Server may be down.", nil);

                break;

            case NSURLErrorNotConnectedToInternet:

                errorMsg = NSLocalizedString(@"Cannot connect to the internet. Service may not be available.", nil);

                break;

            default:

                errorMsg = [error localizedDescription];

                break;

        }

    } else {

        errorMsg = [error localizedDescription];

    }

 

    UIAlertView *av = [[UIAlertView alloc] initWithTitle:

        NSLocalizedString(@"Error Loading Page", nil)

        message:errorMsg delegate:self

        cancelButtonTitle:@"Cancel" otherButtonTitles:nil];

    [av show];

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容