NSError

作者: 喜欢就可以 | 来源:发表于2016-03-10 10:32 被阅读119次

参考文档 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];

}

相关文章

网友评论

      本文标题:NSError

      本文链接:https://www.haomeiwen.com/subject/lejtlttx.html