Epub.js - PhoneGap的不工作,因为斑点的URI [英] Epub.js - Phonegap not working because of blob URI

查看:602
本文介绍了Epub.js - PhoneGap的不工作,因为斑点的URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Epub.js库呈现在PhoneGap的项目.epub文件。

I'm using Epub.js library to render a .epub file in a Phonegap project.

该文件获取获取正确解压缩,但随后会显示空白屏幕如果WebView中运行(在桌面上和Android浏览器运行完美(Chrome应用程式))。

The file gets fetched and unzipped correctly, but then the screen is displayed blank if running in WebView (Works perfect in Desktop and in android browser (Chrome app)).

调试,我看到 IFRAME 应加载的EPUB不起作用,因为 iframe.onload 不会被调用。他试图访问的网址
斑点:文件%3A /// 85a6ce73-2b5f-430E-a908-26a7d3d830e4 ,所以我猜这可能是原因...科尔多瓦不接受一滴 URI方案。

Debugging, I see that the iframe where the epub should be loaded doesn't work, as iframe.onload never gets called. The URL he's trying to access is blob:file%3A///85a6ce73-2b5f-430e-a908-26a7d3d830e4, so I'm guessing that could be the reason... Cordova doesn't accept blob URI schemes.

不过,我不知道有什么解决办法?我完全卡在那里。

However, I don't know any workaround... I'm completely stuck there.

推荐答案

我得到了解决。这个问题的答案都科尔多瓦不接受URI始终是白名单

I got the solution. The answer to all "Cordova doesn't accept URI" is always "Whitelist"

使用白名单插件,我在我的配置文件:

With the whitelist plugin I had in my config file:

<access origin="*" />

不过,调试我看到斑点:/文件:// ... URI是被阻塞在shouldAllowNavigation。然后我试着用:

However, debugging i saw that the blob:/file://...uri was getting blocked in shouldAllowNavigation. Then I tried with:

<access origin="*" />
<allow-navigation origin="*" />

但是!它仍然没有奏效。调试多一点,我看到WhitelistPlugin如果添加了一个 * 它不允许一切,但只有的http:// 的https:// 数据:。最后,加入:

But! it still didn't work. Debugging a bit more, I saw that the WhitelistPlugin if you add a *it doesn't allow everything, but only http://, https://and data:. Finally, adding:

<access origin="*" />
<allow-navigation href="*" />
<allow-navigation href="blob:*" />

修正了我的问题。

Fixed the issue for me.

另外,以防万一它是有用的人,而我的测试,我尝试从服务器下载文件.epub和文件系统提取它(/数据/数据​​/包/ ...),并对其进行访问那里。出于某种原因,访问与XHR本地文件的请求,返回状态:0 ,喜欢它失败了,但响应是存在的。我不得不修改 EPUBJS.core.request 设置方法接受的反应,如果 this.response epub.js文件(而不是期待 this.status 200 )。

Also, just in case it's helpful for someone, while I was testing, I tried downloading the .epub file from a server and extracting it in the filesystem (/data/data/package/...) and accessing it from there. For some reason, accessing local files with XHR Requests returns status: 0, like it failed, but the response is there. I had to edit epub.js file EPUBJS.core.requestmethod to accept responses if this.response is set (instead of expecting this.statusto be 200).

这篇关于Epub.js - PhoneGap的不工作,因为斑点的URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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