jquery - 不允许加载本地资源 ios9 cordova app
<p><p></p><div class="snippet"data-lang="js"data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><!--CSP Meta Tags in index.html -->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no">
<meta http-equiv="Content-Security-Policy"
content="default-src *;
style-src 'self' 'unsafe-inline' 'unsafe-eval';
script-src 'self' 'unsafe-inline' 'unsafe-eval';">
<title>Test App</title>
</head>
<!-- config.xml file with whitelist plugin -->
<?xml version="1.0" encoding="utf-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.abc.testApp"
versionCode = "10"
version = "2.0.0" >
<name>TestApp</name>
<description>
Sample app to download and launch hybrid app
</description>
<author email="[email protected]" href="http://1ct.es">
Test
</author>
<preference name="orientation" value="portrait" />
<preference name="fullscreen"value="true" />
<preference name="webviewbounce" value="false" />
<icon src="icon.png" />
<content src="index.html" />
<gap:platform name="ios" />
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
<gap:plugin name="org.apache.cordova.file" version="1.3.3" />
<gap:plugin name="org.apache.cordova.file-transfer" version="0.5.0" />
<gap:plugin name="org.apache.cordova.inappbrowser" version="0.5.2" />
<gap:plugin name="org.chromium.zip" version="2.1.0" />
<gap:config-file platform="ios" parent="NSAppTransportSecurity">
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</gap:config-file>
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" />
</widget></code></pre>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>所以我已经为此苦苦挣扎了很多。
最新的 iOS 使用 WKWebView。它似乎将本地文件视为来自远程服务器,即使它们位于应用程序本身中,并且此类请求被阻止。引用 <a href="https://www.scirra.com/blog/ashley/25/hacking-something-useful-out-of-wkwebview" rel="noreferrer noopener nofollow">Source</a> </p>
<p>以下解决方案对我有用:</p>
<ol>
<li><p>添加 Corodova 文件插件。</p>
<p><code>cordova插件添加cordova-plugin-file</code></p></li>
<li><p>把本地文件路径改成这样:</p>
<p><code>cdvfile://localhost/bundle/www/you_folder_name/file_name.mp3</code></p></li>
</ol></p>
<p style="font-size: 20px;">关于jquery - 不允许加载本地资源 ios9 cordova app,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33773877/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33773877/
</a>
</p>
页:
[1]