UIWebView 无法正确读取某些本地 HTML5 内容 [英] UIWebView cannot read correctly some local HTML5 stuff
问题描述
我为你们所有人带来了一个新挑战,Objective-C 开发人员:
Here I come with a new challenge for you all, Objective-C developers:
我正在尝试将一些来自 Articulate 的 HTML5 导出加载到 UIWebView 中.嗯,乍一看很简单:只需将 HTML5 资源放入项目并调用 index.html.
I'm trying to load some HTML5 exports from Articulate into an UIWebView. Well, at first sight it's quite simple: just put the HTML5 resources into the project and call index.html.
好吧,如果 HTML5 资源具有复杂的 javascript 结构,那根本行不通.特别是 和
标签.
Well, that simply doesn't work if the HTML5 resource have a complex javascript structure. Specially with <audio>
and <video>
tags.
有什么想法吗?
推荐答案
我已经研究了几个小时,解决方案出现了一些横向思维:
I've been investigating for hours and the solution appeared with some lateral thinking:
如果主要问题是本地阅读不起作用,但应用要求强制您离线维护内容,那么让我们在本地提供内容!.
If the main problem is that reading locally doesn't work, but the app requirements forces you to maintain the content offline, then let's serve the content locally!.
以下是我为解决此问题而遵循的步骤:
Here are the steps I followed to resolve this issue:
- 将网络服务器嵌入到您的应用中(我更喜欢 GCDWebServer)
- 让 GDCWebServer 在本地提供您的故事情节:
[webServer startWithOptions:@{@"BindToLocalhost": @YES} error:nil];
- 使用
WKWebView
调用您的本地网络服务器:[wkView loadRequest:[NSURLRequest requestWithURL:webServer.serverURL]];
- Embed a web server into your app (I prefer GCDWebServer)
- Let GDCWebServer serve your storyline locally with:
[webServer startWithOptions:@{@"BindToLocalhost": @YES} error:nil];
- Use
WKWebView
to call your local web server with:[wkView loadRequest:[NSURLRequest requestWithURL:webServer.serverURL]];
然后,您将在使用 iOS8 的窗口内看到您的 Articulate 故事情节在您的应用中完美运行.
Then you will see your Articulate storyline working perfectly in your app inside a window, with iOS8.
希望这可以帮助某人.
这篇关于UIWebView 无法正确读取某些本地 HTML5 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!