【问题标题】:what cause error NSNetServicesErrorCode = "-72000"?什么导致错误 NSNetServicesErrorCode = "-72000"?
【发布时间】:2012-05-19 23:28:27
【问题描述】:

我创建了一个简单的浏览器,可以使用 UIWebview 加载本地文件。起初,当我尝试预览 html 文件时,uiwebview 可以加载源文件并进行预览。但是在我最小化应用程序(应用程序进入后台),然后再次打开应用程序后,我得到了这个错误:

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

应用没有崩溃,但旋转指示器永远不会停止。

有人能告诉我是什么原因造成的吗?以及如何解决?

谢谢你:)

【问题讨论】:

  • 你能展示一下你是如何初始化网络视图的吗?
  • 如果在 Mac 上发生这种情况,这可能意味着应用程序已被沙盒化(您可以在授权文件中检查)。仅适用于其他偶然发现此问题的人。

标签: ipad ios5 uiwebview nsnetservice


【解决方案1】:

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

你电脑上的 localhost 就是你的电脑,你 ipad 上的 localhost 就是你的 ipad - 用于测试使用可解析的域名或 ip 地址。

【讨论】:

  • 我在连接到某个本地 IP 时收到相同的错误代码。或者更确切地说,将我的服务器推送到本地网络并通过 192.x.y.z 访问它。因此赏金。
  • 您确定 ipad 可以访问该网址吗?尝试在 ipad 浏览器地址栏中输入它以确保确定。
  • 一旦发生此错误,我无法从本地网络中的任何设备访问它。通常我可以毫无问题地发布 Web 服务,然后可以从任何设备(iPad、Macbook、Android Phone、Windows PC 等)访问它。但有时我会收到此错误,并且很想知道错误代码试图告诉我什么。
  • 如果您无法访问它,那么问题出在服务器端。错误代码 -72000 是“未知错误”,所以它告诉你的只是这不是任何常见的东西,但没有详细说明。
  • 是的,当然这是服务器端的重点。 iPhone 将网页提供给本地网络中的设备。我正在发布服务器,有时,在发布时我也收到提问者的错误:/
【解决方案2】:

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

};

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

一般来说,我总是查阅头文件以获取错误代码。它们几乎总是由枚举值分配,并且枚举的名称通常比使用的数字更具描述性。

【讨论】:

  • -72000 实际上是“未知”错误,而不是碰撞错误。
【解决方案3】:

Sergiu Todirascu 在问题中的评论为我解决了这个问题。 Mac 沙盒导致此问题,我必须在权利选项卡中打开网络,在我的情况下,传入和传出网络复选框。创建一个答案,以便更容易看到。

【讨论】:

  • 这与 iOS 相关吗?
猜你喜欢
  • 2011-08-06
  • 1970-01-01
  • 2011-06-25
  • 2021-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-28
相关资源
最近更新 更多