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

}

你可能感兴趣的:(NSError)