0

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

我将如何对这些可能的错误进行分类,我想将其显示为“找不到指定的主机名”“url 超时错误”等。

4

2 回答 2

1

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

于 2012-07-26T09:20:34.717 回答
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];
于 2012-07-30T08:36:12.713 回答