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

查看:135
本文介绍了允许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 <形式的网址/ a>

The UIWebView is loading URLs of the form 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加载,并且如果您没有网络连接,将解决早期HTTP协议失败的SDK的问题。

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天全站免登陆