Ipad 什么原因导致错误NSNetServicesErrorCode="-72000“吗;?

Ipad 什么原因导致错误NSNetServicesErrorCode="-72000“吗;?,ipad,ios5,uiwebview,nsnetservice,Ipad,Ios5,Uiwebview,Nsnetservice,我创建了一个简单的浏览器,可以使用UIWebview加载本地文件。首先,当我尝试预览html文件时,uiwebview可以加载源文件并预览它。但当我最小化应用程序(应用程序进入后台),然后再次打开应用程序后,我出现以下错误: Error Dict: { NSNetServicesErrorCode = "-72000"; NSNetServicesErrorDomain = 10; } 在此之后,uiwebview无法加载源文件,当我在(void)webView:(uiwebv

我创建了一个简单的浏览器,可以使用UIWebview加载本地文件。首先,当我尝试预览html文件时,uiwebview可以加载源文件并预览它。但当我最小化应用程序(应用程序进入后台),然后再次打开应用程序后,我出现以下错误:

Error Dict: {
    NSNetServicesErrorCode = "-72000";
    NSNetServicesErrorDomain = 10;
}
在此之后,uiwebview无法加载源文件,当我在
(void)webView:(uiwebview*)webView didFailLoadWithError:(nError*)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."}
应用程序没有崩溃,但旋转指示灯从不停止

谁能告诉我这件事的原因吗?如何解决呢


谢谢:)

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


计算机上的Localhost是您的计算机,ipad上的Localhost是您的ipad-用于测试,请使用可解析的域名或ip地址。

如果查看
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,

};
您将收到服务冲突错误,这意味着具有相同域、类型和名称的网络服务已在您的网络上发布其服务


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

Sergiu Todirascu在问题中的评论为我解决了这个问题。Mac沙箱导致了这一点,我必须打开“权利”选项卡中的“网络”复选框(在我的例子中是“传入”和“传出”网络复选框)。创建一个更容易看到的答案

你能展示一下你是如何初始化web视图的吗?如果这发生在Mac上,这可能意味着应用程序是沙盒的(你可以在授权文件中检查)。对于其他遇到这个问题的人,我会在连接到某个本地IP时收到相同的错误代码。或者把我的服务器推到本地网络,通过192.x.y.z访问它。你确定ipad可以访问这个url吗?请尝试在iPad浏览器地址栏中键入以确定。一旦发生此错误,我将无法从本地网络中的任何设备访问它。通常我可以毫无问题地发布web服务,然后可以从任何设备(iPad、Macbook、Android手机、Windows PC等)访问它。但有时我会遇到这个错误,我很想知道错误代码试图告诉我什么。如果你不能访问它,那么问题就出在服务器端。错误代码-72000是“未知错误”,所以它告诉你的是,这不是一般的错误,但没有详细说明。是的,当然这是服务器端的问题。iPhone正在为本地网络中的设备提供网页服务。我正在发布服务器,有时候,在发布的时候,我也会遇到一个问题:询问者的问题是:/
-72000
实际上是“未知”错误,而不是冲突错误。这与iOS相关吗?