什么导致错误NSNetServicesErrorCode =“-72000”?

问题描述:

我创建了一个简单的浏览器,可以使用UIWebview加载本地文件。起初,当我尝试预览一个html文件时,uiwebview可以加载源文件并预览它。但之后,我最小化的应用程序(应用程序进入后台),然后再次打开该应用程序中,我得到这个错误:什么导致错误NSNetServicesErrorCode =“-72000”?

Error Dict: { 
    NSNetServicesErrorCode = "-72000"; 
    NSNetServicesErrorDomain = 10; 
} 

,并在这之后,一个UIWebView无法加载源文件,当我登录在(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error错误,它显示了这个消息:

Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo=0x53d610 {NSErrorFailingURLStringKey=http://localhost:9898/local/a.html?83C66B33-874C-41A7-BBF5-78D1615512DF, NSErrorFailingURLKey=http://localhost:9898/local/a.html?83C66B33-874C-41A7-BBF5-78D1615512DF, NSLocalizedDescription=Could not connect to the server., NSUnderlyingError=0x5ccaa0 "Could not connect to the server."} 

的应用程序是不会崩溃,但纺纱指标永不停止。

有人可以告诉我是什么原因导致这种情况?以及如何解决它?

谢谢:)

+0

你能告诉你如何初始化网页视图吗? – sergio

+0

你可以发布一些代码吗? – Hejazi

的问题似乎是你试图连接到主机:http://localhost:9898/local/[..]

本地主机计算机上的是您的计算机,本地主机上你的iPad是你的iPad - 用于测试使用可解析的域名或IP地址。

+0

当连接到一些本地IP时,我得到相同的错误代码。或者将我的服务器推送到本地网络并通过192.x.y.z访问它。为此,赏金。 – Bersaelor

+0

你确定ipad可以访问该网址吗?尝试在iPad的浏览器地址栏中输入,以确保它。 – c2h5oh

+0

一旦发生此错误,我无法从本地网络中的任何设备访问它。通常我可以毫无问题地发布Web服务,然后可以从任何设备(iPad,Macbook,Android Phone,Windows PC等)访问它。但是有时候我得到这个错误,并且很想知道错误代码试图告诉我什么。 – Bersaelor

如果你看看NSNetServices水箱内,你会看到下面的枚举解释每个错误:

typedef NS_ENUM(NSInteger, NSNetServicesError) { 

/* An unknown error occured during resolution or publication. 
*/ 
    NSNetServicesUnknownError = -72000L, 

/* An NSNetService with the same domain, type and name was already present when the publication request was made. 
*/ 
    NSNetServicesCollisionError = -72001L, 

/* The NSNetService was not found when a resolution request was made. 
*/ 
    NSNetServicesNotFoundError = -72002L, 

/* A publication or resolution request was sent to an NSNetService instance which was already published or a search request was made of an NSNetServiceBrowser instance which was already searching. 
*/ 
    NSNetServicesActivityInProgress = -72003L, 

/* An required argument was not provided when initializing the NSNetService instance. 
*/ 
    NSNetServicesBadArgumentError = -72004L, 

/* The operation being performed by the NSNetService or NSNetServiceBrowser instance was cancelled. 
*/ 
    NSNetServicesCancelledError = -72005L, 

/* An invalid argument was provided when initializing the NSNetService instance or starting a search with an NSNetServiceBrowser instance. 
*/ 
    NSNetServicesInvalidError = -72006L, 

/* Resolution of an NSNetService instance failed because the timeout was reached. 
*/ 
    NSNetServicesTimeoutError = -72007L, 

}; 

你得到一个服务冲突错误,这意味着相同的域网服务,类型和名称已在您的网络上发布其服务。

通常,我总是查阅错误代码的头文件。它们几乎总是由一个枚举值分配的,枚举通常具有比所使用的数字更多的描述性名称。