2012-07-26 62 views
0

是他们的任何类别的UIWebView可能的错误?在我的应用程序中,我需要显示加载url时发生的实际错误。我可以打印在didFailLoadWithError方法的错误,但在提供了有关错误类似分类UIWebView错误并显示在iPhone应用程序?

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."} 

我将如何分类,这些可能出现的错误很长的描述,我想喜欢 显示为“指定的主机找不到” “网址超时错误” 等

回答

0

还好,在didFailWithError方法

if (error.code==NSURLErrorTimedOut) { 

     [email protected]"URL Time Out Error "; 

    } 
    else if (error.code==NSURLErrorCannotFindHost) { 
     [email protected]"Cannot Find Host "; 

    } 
     else if (error.code==NSURLErrorCannotConnectToHost) { 
      [email protected]"Cannot Connect To Host"; 

    } 
      else if (error.code==NSURLErrorNetworkConnectionLost) { 
       [email protected]"Network Connection Lost"; 

     } 
        else if (error.code==NSURLErrorUnknown) { 
         [email protected]"Unknown Error"; 

      } 
           else { 
            [email protected]"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]; 
+0

你看到所有那些“其他”?这就是为什么“switch”语句被发明出来的原因 – 2014-03-20 09:08:45

+0

或更好的枚举myEnum {LoadingFaild = -1}词典 dict = new词典();; \t \t \t dict.Add(-1,“LoadingFailed”); \t \t \t Console.WriteLine(“Error loading = {0}”,dict [-1]); – 2014-09-26 14:48:02

+0

或者dict [myEnum.LoadingFailed] – 2014-09-26 14:48:47