ios – Cordova 6 app无法从file:路径加载

ios – Cordova 6 app无法从file:路径加载,第1张

概述我已将现有应用更新到Cordova 6.0.0,并且在使用XCode 7.2.1定位iOS 9的iOS设备上运行它时遇到问题. 我已经安装了WKWebView插件:cordova-plugin-wkwebview-engine 1.0.2 运行使用AngularJS构建的应用程序时,它尝试做的第一件事就是打开一个json文件: $http.get('data/config.json').succe 我已将现有应用更新到Cordova 6.0.0,并且在使用XCode 7.2.1定位iOS 9的iOS设备上运行它时遇到问题.

我已经安装了WKWebVIEw插件:cordova-plugin-wkwebvIEw-engine 1.0.2

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

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

但是我们在Web视图控制台中收到此错误:

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.”

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

解决方法 编辑:

离子团队一直在研究WKWebVIEwEngine插件的一个分支,并修复了一些XHR问题,不确定这个问题是否已修复.你可以看看https://github.com/driftyco/cordova-plugin-wkwebview-engine

老答案:
这是一个已知问题,WKWebVIEwEngine中不允许使用本地文件:// url XmlhttpRequests(https://issues.apache.org/jira/browse/CB-10143)

有关更多已知问题,请参阅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).

它们都将使用本地Web服务器来解决一些已知的WKWebVIEw限制.

总结

以上是内存溢出为你收集整理的ios – Cordova 6 app无法从file://路径加载全部内容,希望文章能够帮你解决ios – Cordova 6 app无法从file://路径加载所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1075214.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存