如何允许 Cordova 6.1 应用程序从网站将 iframe 嵌入到 iOS 中?

How can I allow a Cordova 6.1 app to embed an iframe in iOS from a website?

在我最近构建之前,我的 cordova 应用程序能够很好地嵌入网站的 iframe;现在,大概是在我忘记了更新之后,构建应用程序导致 iframe 在 iOS 上为空白,但在 Android.

上有效

我已将以下设置添加到 config.xml:

<access origin="*"/> <access origin="*.pushwoosh.com" /> <access origin="*.hoby.org" /> <allow-navigation href="*" /> <allow-intent href="*" />

以及以下内容安全策略:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

基本上应该允许一切。我添加了 cordova-whitelist 插件,使用 cordova 6.1.0 和 Ionic 1.7.14

编辑:它实际上可以在 iOS 模拟器上运行,但当我 运行 在设备上运行时就不行了。

编辑 2:看起来可能是移动 safari 的问题;我正在通过我的网络查看文件,甚至在 Cordova 之外,它们也没有正确加载。我可以确认这至少在几天前是有效的。

您的 whitelist 插件应用程序已关闭,但可能失败,因为您的 index.html 中有 javascript。 CSP 阻止了很多开发者。最简单的做法是将所有 Javascript 和 CSS 移动到它们自己的单独文件中。

除此之外,这是一个广泛应用的解决方案:

附带说明,自 Cordova Tools 5.0.0 (April 21, 2015). For Phonegap Build, that means since cli-5.1.1(2015 年 6 月 16 日)起需要 whitelist 系统

将此添加到您的 config.xml

<plugin name="cordova-plugin-whitelist"      source="npm" spec="1.1.0" />
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" /> <!-- Required for iOS9 -->

请注意,您的应用现在不安全。保护您的应用程序取决于您。
将以下内容添加到您的 index.html

<meta http-equiv="Content-Security-Policy" 
         content="default-src *; 
                  style-src * 'self' 'unsafe-inline' 'unsafe-eval'; 
                  script-src * 'self' 'unsafe-inline' 'unsafe-eval';">

请注意,您的应用现在不安全。保护您的应用程序取决于您。
白名单 工作表应该有所帮助。
HOW TO apply the Cordova/Phonegap the whitelist system