UIWebView 无法正确读取某些本地 HTML5 内容 [英] UIWebView cannot read correctly some local HTML5 stuff

查看:29
本文介绍了UIWebView 无法正确读取某些本地 HTML5 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为你们所有人带来了一个新挑战,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:

  1. 将网络服务器嵌入到您的应用中(我更喜欢 GCDWebServer)
  2. 让 GDCWebServer 在本地提供您的故事情节:[webServer startWithOptions:@{@"BindToLocalhost": @YES} error:nil];
  3. 使用 WKWebView 调用您的本地网络服务器:[wkView loadRequest:[NSURLRequest requestWithURL:webServer.serverURL]];
  1. Embed a web server into your app (I prefer GCDWebServer)
  2. Let GDCWebServer serve your storyline locally with: [webServer startWithOptions:@{@"BindToLocalhost": @YES} error:nil];
  3. 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屋!

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