使用 Cordova 3.7 从 iOS 8 上的 www 文件夹加载资源 (file://)

2024-03-19

我有一个混合应用程序,可以使用 Cordova 3.7 和 jQuery Mobile 1.3.2 在 iOS 7 上完美运行

我正在 iOS 8 上测试它,但它坏了。 我使用绝对路径请求应用程序的每个页面(视图),使用file://协议,例如:

file:///var/mobile/Applications/<UUID>/MyApp.app/www/views/add-project.html

但我收到错误:

Failed to load resource: The requested URL was not found on this server.

我读到this bug http://www.openradar.me/radar?id=5839348817723392,是这个问题吗?

另外,在 iOS 8 上,www 文件夹的位置与 iOS 7 略有不同,它解析为:

file:///var/mobile/Containers/Data/Application/<UUID>/MYApp.app/www/views/add-project.html

它是否正确?

我尝试使用 toURL() 和 toInternalURL() 方法来获得绝对路径,例如:

cdvfile://localhost/root/var/mobile/Containers/Bundle/Application/<UUID>/MyApp.app/但我总是遇到同样的错误。 有什么建议吗?

Thanks


对于任何可能觉得这有用的人,我终于设法解决了这个问题。

完整路径wwwios 8+ 上的文件夹是:

file:///private/var/mobile/Containers/Bundle/Application/<UUID>/<your_app>.app/www/

但是当您使用 Cordova 请求应用程序目录时,执行以下操作:

window.resolveLocalFileSystemURL(cordova.file.applicationDirectory, onSuccess, onError);

它会给你一个错误的路径(iOS 8.1.2 上的 Cordova 3.7),例如:

file:////var/mobile/Containers/Bundle/Application/<UUID>/<your_app>.app/

使用文档中建议的 toURL() 方法

因此您需要手动进行一些调整

var path = fileSystem.toURL();//given by the success callback 

IOS_ASSETS_ABS_PATH = path.replace("file:////", "file:///private/");

IOS_ASSETS_ABS_PATH += "www/";

宾果游戏!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Cordova 3.7 从 iOS 8 上的 www 文件夹加载资源 (file://) 的相关文章

随机推荐