允许 UIWebView 在没有 Internet 连接的情况下加载 http://localhost:port/path URI [英] Allow UIWebView to load http://localhost:port/path URIs without an Internet connection

查看:14
本文介绍了允许 UIWebView 在没有 Internet 连接的情况下加载 http://localhost:port/path URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 iPad 应用程序,它有一个在高端口上侦听的嵌入式 HTTP 服务器,我正在使用 UIWebView 从这个 HTTP 服务器加载页面.

I am working on an iPad app which has an embedded HTTP server listening on a high port, and I am loading pages from this HTTP server using a UIWebView.

对于应用程序的功能,重要的是它在没有可用网络连接时工作.

For the functionality of the app, it is important that this works when no network connection is available.

UIWebView 正在加载格式为 http://localhost:port/path

当我在 iPad 上禁用 Wi-Fi 并运行应用程序时,UIWebView 的委托会收到带有以下 NSError 对象的 webView:didFailLoadWithError: 消息:

When I disable Wi-Fi on my iPad and run the application, the UIWebView’s delegate gets a webView:didFailLoadWithError: message with the following NSError object:

Error Domain=NSURLErrorDomain Code=-1009 UserInfo=0x1b4a50 "no Internet connection"

很明显,SDK 很聪明,检测到它没有 Internet 连接,但应该可以在没有 Internet 连接的情况下访问 127.0.0.1/localhost/::1.我将向 Apple 报告此错误,但同时在此征求有关此 SDK 错误的可能解决方法的建议.

Clearly the SDK is being clever and detecting that it has no Internet connection, but it should be possible to access 127.0.0.1/localhost/::1 without an Internet connection. I will report the bug to Apple but am asking here for advice about possible workarounds for this SDK bug in the meantime.

请注意:更改应用程序的架构不在此问题的范围内.

Please note: changing the architecture of the application is not in scope for this question.

推荐答案

您可能想研究定义自己的方案并使用 NSURLProtocol 来实现它,而不是运行 HTTP 服务器.这将允许您在无需实现 HTTP 协议的情况下处理 URL 的加载,并且可以通过 SDK 解决此问题,如果您没有网络连接,则 HTTP 协议会提前失败.

You may want to investigate defining your own scheme and implementing it with NSURLProtocol instead of running an HTTP server. This will allow you to handle the loading of URLs without having to implement the HTTP protocol, and will get around this issue with the SDK where the HTTP protocol fails early if you have no network connection.

这篇关于允许 UIWebView 在没有 Internet 连接的情况下加载 http://localhost:port/path URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆