gpt4 book ai didi

ios - Cordova 6 应用程序无法从文件 ://path 加载

转载 作者:可可西里 更新时间:2023-11-01 04:28:40 28 4
gpt4 key购买 nike

我已经将一个现有的应用程序更新到 Cordova 6.0.0,但在带有针对 iOS 9 的 XCode 7.2.1 的 iOS 设备上运行它时遇到问题。

我已经安装了WKWebView插件:cordova-plugin-wkwebview-engine 1.0.2

当运行使用 AngularJS 构建的应用程序时,它尝试做的第一件事就是打开一个 json 文件:

$http.get('data/config.json').success(function(data) {
// do stuff
});

但是我们在 web View 控制台中得到这个错误:

XMLHttpRequest cannot load file:///var/mobile/Containers/Bundle/Application/
E9D74C94-ADC6-410F-9F41-7CE63CB7877F/Milk.app/www/data/config.json. Cross
origin requests are only supported for HTTP.

在 config.xml 文件中我们有:

<access origin="*" subdomains="true" />

为什么 file:// 请求会像这样被阻止,我该如何解决?

*编辑*

根据plugin page :

"In iOS 9, Apple has fixed the issue present through iOS 8 where you cannot load locale files using file://, and must resort to using a local webserver. However, you are still not able to use XHR from the file:// protocol without CORS enabled on your server."

“您的服务器” 是什么意思?什么服务器?我们正在加载本地文件,没有服务器!

最佳答案

编辑:

ionic 团队一直致力于 WKWebViewEngine 插件的分支,并修复了一些 XHR 问题,不确定这个是否已修复。你可以上https://github.com/driftyco/cordova-plugin-wkwebview-engine看看

旧答案:这是一个已知问题,WKWebViewEngine ( https://issues.apache.org/jira/browse/CB-10143 )

不允许本地 file:// url XmlHttpRequests

有关更多已知问题,请参阅 https://issues.apache.org/jira/browse/CB-10237?jql=labels%20%3D%20wkwebview-known-issues

如果你想让本地 ajax 调用工作,你应该使用 wkwebview-engine-localhost 插件(https://github.com/apache/cordova-plugins/tree/master/wkwebview-engine-localhost)

或者 Telerik 的 WKWebView 插件 ( https://github.com/Telerik-Verified-Plugins/WKWebView )。

它们都将使用本地网络服务器来解决一些已知的 WKWebView 限制。

关于ios - Cordova 6 应用程序无法从文件 ://path 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35754884/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com