Cordova白名单插件不起作用

时间:2016-06-18 09:48:07

标签: javascript cordova ionic-framework

我的应用在浏览器上工作正常,但在设备上无效: 离子应用程序仅加载HTML和CSS,但不加载http请求并运行JS。

在Xcode中它停留在这一点:

2016-06-18 11:43:59.169 waettr[719:414729] Apache Cordova native platform version 4.1.0 is starting.
2016-06-18 11:43:59.170 waettr[719:414729] Multi-tasking -> Device: YES, App: YES
2016-06-18 11:43:59.203 waettr[719:414729] Using UIWebView
2016-06-18 11:43:59.204 waettr[719:414729] [CDVTimer][handleopenurl] 0.057995ms
2016-06-18 11:43:59.205 waettr[719:414729] [CDVTimer][intentandnavigationfilter] 1.080990ms
2016-06-18 11:43:59.205 waettr[719:414729] [CDVTimer][gesturehandler] 0.043035ms
2016-06-18 11:43:59.217 waettr[719:414729] [CDVTimer][splashscreen] 12.061000ms
2016-06-18 11:43:59.224 waettr[719:414729] [CDVTimer][statusbar] 6.388009ms
2016-06-18 11:43:59.224 waettr[719:414729] [CDVTimer][keyboard] 0.630975ms
2016-06-18 11:43:59.225 waettr[719:414729] [CDVTimer][TotalPluginStartup] 20.883977ms
2016-06-18 11:43:59.366 waettr[719:414729] Resetting plugins due to page load.
2016-06-18 11:44:01.708 waettr[719:414729] Finished load of: file:///var/containers/Bundle/Application/8365EFD8-1FAA-4E82-8DB6-2ADCD8E53A90/waettr.app/www/index.html#/home

我有以下设置:

  <access origin="*" />
  <allow-navigation href="https://maps.googleapis.com/*"/>
  <allow-navigation href="http://api.openweathermap.org/*"/>

此标记:

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

我的错误是什么?我从此头疼......

1 个答案:

答案 0 :(得分:1)

如果您正在进行Ajax调用:

 <allow-navigation href="https://maps.googleapis.com/*"/>
 <allow-navigation href="http://api.openweathermap.org/*"/>

我猜你的config.xml中有这些,然后我建议您更新内容安全策略元标签以包含connect-src声明。这定义了您可以在哪里进行Ajax调用。

尝试设置以下内容安全策略:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' maps.googleapis.com 'unsafe-inline' 'unsafe-eval'; connect-src https://maps.googleapis.com http://api.openweathermap.org">

在这里,我添加了connect-src以及我认为您尝试向其发出Ajax请求的URL。如果您想了解更多相关信息,请点击relevant blog post