【问题标题】:PhoneGap/Cordova compiled android app doesn't load external URIsPhoneGap/Cordova 编译的 android 应用程序不加载外部 URI
【发布时间】:2016-05-04 02:58:53
【问题描述】:

我正在尝试制作一个简单的地理定位应用程序。本地地理定位在坐标输入时工作正常。我很难加载谷歌地图,like in the Simple Markers example here

Turns out you have to whitelist external domains。没问题,我在 config.xml 中添加了以下内容(在 phonegap 应用程序的根目录中):

<access origin="*" />
<access origin="*://*.googleapis.com/*" subdomains="true" />
<access origin="*://*.gstatic.com/*" subdomains="true" />
<access origin="*://*.google.com/*" subdomains="true" />
<access origin="*://*.googleusercontent.com/*" subdomains="true" />

以防万一,我在&lt;platform name="android"&gt; 下添加了相同的内容。然后我删除了它。依然没有。

然后我让应用显示一个简单的图像;这是应用程序的 HTML 部分的样子:

<body>
    <span><img src="https://maps.gstatic.com/mapfiles/api-3/images/spotlight-poi_hdpi.png" alt="" /></span>
    <div id="map"></div>
</body>

如果我在浏览器中打开这个文件,没关系:

但是当我编译应用程序并在我的平板电脑上打开它时,呃哦:

所以看起来访问权限设置不正确。图片坏了,googleapis.com 永远不会加载,我的地图永远也看不到曙光。

我的根 config.xml 文件的Here is a pastebin

请帮我弄清楚为什么 android 应用拒绝在 PhoneGap/Cordova 的上下文中加载外部 url。

我赌的是一些我不知道的晦涩的权限。我的头撞墙有一段时间了,真的很感激一些帮助。提前致谢。

【问题讨论】:

    标签: javascript android cordova google-maps phonegap-build


    【解决方案1】:

    鉴于您已将 * 作为来源列入白名单,您甚至不需要 Google 的来源。您是否尝试过从 Chrome 检查应用程序?在桌面浏览器中转到 chrome://inspect,如果设备已连接到您的计算机,您可以从那里检查应用程序。

    检查器中的控制台应显示您的请求所产生的任何错误。我猜你有一个阻止请求的内容安全策略。最新版本的白名单文档位于 https://github.com/apache/cordova-plugin-whitelist。在自述文件的底部,您将看到一些内容安全策略示例。我建议将以下内容添加到您的 index.html:

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *">
    

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-26
      • 2014-09-06
      • 1970-01-01
      相关资源
      最近更新 更多