分类UIWebView错误并在iPhone应用程序上显示?

时间:2012-07-26 08:44:15

标签: iphone uiwebview

是UIWebView可能出错的任何类别吗?在我的应用程序中,我需要显示加载URL时发生的实际错误。我可以在didFailLoadWithError方法中打印错误,但是给出了一个关于错误的长描述

didFailLoadWithError Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo=0x895fb10 {NSErrorFailingURLStringKey=https://mobilelogin.bwanet.ca/mdninput.html?csphostid=J13y8E9t000Mb3ZK00001H7R, NSErrorFailingURLKey=https://mobilelogin.bwanet.ca/mdninput.html?csphostid=J13y8E9t000Mb3ZK00001H7R, NSLocalizedDescription=A server with the specified hostname could not be found., NSUnderlyingError=0x8c68f20 "A server with the specified hostname could not be found."}

我将如何对这些可能的错误进行分类,我希望将其显示为 “无法找到指定的主机名” “网址超时错误” 等

2 个答案:

答案 0 :(得分:1)

在这篇文章中,您可以找到可能的错误代码列表,这些代码可以帮助您使用特定的错误字符串对其进行分类:Undocumented NSURLErrorDomain error codes (-1001, -1003 and -1004) using StoreKit

答案 1 :(得分:0)

好的,在didFailWithError方法

if (error.code==NSURLErrorTimedOut) {

      errorReason=@"URL Time Out Error ";

   }
    else if (error.code==NSURLErrorCannotFindHost) {
      errorReason=@"Cannot Find Host ";

   }
       else if (error.code==NSURLErrorCannotConnectToHost) {
           errorReason=@"Cannot Connect To Host";

    }
             else if (error.code==NSURLErrorNetworkConnectionLost) {
               errorReason=@"Network Connection Lost";

       }
                   else if (error.code==NSURLErrorUnknown) {
                        errorReason=@"Unknown Error";

             }
                               else {
                                   errorReason=@"Loading Failed";

                   }
 UIAlertView *errorAlert=[[UIAlertView alloc]initWithTitle:errorReason message:@"Redirecting to the server failed. do you want to EXIT the app"  delegate:self cancelButtonTitle:@"EXIT" otherButtonTitles:@"RELOAD", nil];


  [errorAlert show];
  [errorAlert release];