在 Android Lollipop 5.0 的 Phonegap 中将 URL 列入白名单
Whitelisting URL's in Phonegap for Android Lollipop 5.0
这让我抓狂,所以迫不及待地想在 Android 5.* 中开始测试,就这样吧。
首先这是我所拥有的:
config.xml
<access origin="*.google.com"/>
<access origin="*.gstatic.com"/>
<access origin="*.googleapis.com"/>
...
<plugin name="cordova-plugin-whitelist" version="1" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
index.html
<head>
...
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' https://*.google.com; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' https://*.gstatic.com; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' https://*.googleapis.com; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
我发现描述了同样的问题here, and attempted to merge the suggestions found, along with some other advice from the PhoneGap Documentation,还没有成功。
为了更具体地说明这个问题,我试图允许的资源是 Google Maps V3。我确定我遗漏了一些小东西,我会感激任何东西,即使是一个简单的建议。
谢谢!
更新 1
很好,@Fido,但不幸的是,事实证明这不是唯一的问题。我现在正在使用 here 记录的 PhoneGap 插件,并在我的 config.xml 中替换,但没有改进。有趣的是,我注意到该插件并未显示为在项目的插件摘要中使用(我现在发现它存在)。所以,我想说的是,尽管有文档,它很可能无法按照描述的方式提取此资源。
我会给任何人提供任何额外建议的机会,但最终我可能不得不硬着头皮按照 Fido 的建议进行本地构建。
更新 2
事实证明,我没有正确地将我的 config.xml 推送到存储库,所以它现在反映出我正在使用 whitelist plugin provided by Corova,但没有帮助。在我构建本地并使用其他建议的插件之前,我会看看是否有任何插件。
更新 3
好消息;我能够从 here:
指定相同插件的 NPM 包
<gap:plugin name="cordova-plugin-whitelist" version="1.0.0" source="npm" />
据我所知,它是你建议的镜像@Fido(如果我错了请纠正我)但问题仍然存在;我只能想象这是我的起源、允许意图或内容安全策略定义不正确。
谢谢!
使用 Cordova 4.0 及更高版本时,您需要添加 this 插件以使白名单正常工作。
在你的情况下,因为你使用的是 phonegap 构建平台,这一行:
<plugin name="cordova-plugin-whitelist" version="1" />
实际上应该是这样的:
<gap:plugin name="cordova-plugin-whitelist" version="1" />
如果云服务被证明过于有限,那么您可以使用 CLI 安装 cordova 插件,然后在本地构建和部署。
有关此方法的更多信息 here。这种方法需要更多的设置工作(例如获取 android sdk),但在我看来,运行 的开发速度要快得多。
这让我抓狂,所以迫不及待地想在 Android 5.* 中开始测试,就这样吧。
首先这是我所拥有的:
config.xml
<access origin="*.google.com"/>
<access origin="*.gstatic.com"/>
<access origin="*.googleapis.com"/>
...
<plugin name="cordova-plugin-whitelist" version="1" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
index.html
<head>
...
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' https://*.google.com; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' https://*.gstatic.com; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' https://*.googleapis.com; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
我发现描述了同样的问题here, and attempted to merge the suggestions found, along with some other advice from the PhoneGap Documentation,还没有成功。
为了更具体地说明这个问题,我试图允许的资源是 Google Maps V3。我确定我遗漏了一些小东西,我会感激任何东西,即使是一个简单的建议。
谢谢!
更新 1
很好,@Fido,但不幸的是,事实证明这不是唯一的问题。我现在正在使用 here 记录的 PhoneGap 插件,并在我的 config.xml 中替换,但没有改进。有趣的是,我注意到该插件并未显示为在项目的插件摘要中使用(我现在发现它存在)。所以,我想说的是,尽管有文档,它很可能无法按照描述的方式提取此资源。
我会给任何人提供任何额外建议的机会,但最终我可能不得不硬着头皮按照 Fido 的建议进行本地构建。
更新 2
事实证明,我没有正确地将我的 config.xml 推送到存储库,所以它现在反映出我正在使用 whitelist plugin provided by Corova,但没有帮助。在我构建本地并使用其他建议的插件之前,我会看看是否有任何插件。
更新 3
好消息;我能够从 here:
指定相同插件的 NPM 包<gap:plugin name="cordova-plugin-whitelist" version="1.0.0" source="npm" />
据我所知,它是你建议的镜像@Fido(如果我错了请纠正我)但问题仍然存在;我只能想象这是我的起源、允许意图或内容安全策略定义不正确。
谢谢!
使用 Cordova 4.0 及更高版本时,您需要添加 this 插件以使白名单正常工作。
在你的情况下,因为你使用的是 phonegap 构建平台,这一行:
<plugin name="cordova-plugin-whitelist" version="1" />
实际上应该是这样的:
<gap:plugin name="cordova-plugin-whitelist" version="1" />
如果云服务被证明过于有限,那么您可以使用 CLI 安装 cordova 插件,然后在本地构建和部署。 有关此方法的更多信息 here。这种方法需要更多的设置工作(例如获取 android sdk),但在我看来,运行 的开发速度要快得多。