[英]PhoneGap/Cordova compiled android app doesn't load external URIs
I'm trying to make a simple geolocation app. 我正在尝试制作一个简单的地理位置应用。 The native geolocation works fine in that coordinates are coming in. I'm having a hard time loading a google map, like in the Simple Markers example here . 本地地理位置在输入坐标时效果很好。我很难加载Google地图, 例如此处的“简单标记”示例 。
Turns out you have to whitelist external domains . 原来,您必须将外部域列入白名单 。 No problem, I added the following to my config.xml (in root of the phonegap app): 没问题,我在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" />
Just in case, I added the same under <platform name="android">
. 以防万一,我在<platform name="android">
下添加了相同的内容。 Then I removed it. 然后我将其删除。 Still, nothing. 依然没有。
I then made the app display a simple image; 然后,我使该应用程序显示一个简单的图像; this is what the HTML part of the app looks like: 这是应用程序的HTML部分的样子:
<body>
<span><img src="https://maps.gstatic.com/mapfiles/api-3/images/spotlight-poi_hdpi.png" alt="" /></span>
<div id="map"></div>
</body>
If I open this file in a browser, it's a-ok: 如果我在浏览器中打开此文件,可以:
But when I compile the app and open it on my tablet, uh oh: 但是,当我编译应用程序并在平板电脑上打开它时,哦:
So it looks like the access permissions aren't correctly set. 因此,似乎访问权限设置不正确。 The image is broken, googleapis.com
never loads and my map never sees the light of day. 图片损坏, googleapis.com
永不加载,我的地图也看不到白天。
Here is a pastebin of my root config.xml
file. 这是我的根config.xml
文件的pastebin 。
My bet is on some obscure permissions thing I do not know about. 我的赌注是一些我不知道的模糊权限。 Been banging my head against a wall for a while now, would really appreciate some help. 现在我把头撞在墙上已经有一段时间了,真的很感谢您的帮助。 Thanks in advance. 提前致谢。
Given that you've whitelisted * as an origin, you shouldn't even need the Google ones. 鉴于您已将*列入了白名单,因此您甚至都不需要Google了。 Have you tried inspecting the app from Chrome? 您是否尝试过通过Chrome检查该应用? Go to chrome://inspect in your desktop browser, and you can inspect the app from there if the device is connected to your computer. 在桌面浏览器中转到chrome:// inspect ,如果设备已连接到计算机,则可以从那里检查该应用。
The console in the inspector should show any errors that your requests are making. 检查器中的控制台应显示您的请求所犯的任何错误。 I'm guessing that you have a Content Security Policy that's blocking the request. 我猜您有一个阻止请求的内容安全策略。 The latest version of the whitelist docs are at https://github.com/apache/cordova-plugin-whitelist . 白名单文档的最新版本位于https://github.com/apache/cordova-plugin-whitelist 。 At the bottom of the readme you'll see a few samples for a Content Security Policy. 在自述文件的底部,您将看到一些内容安全策略的示例。 I suggest adding the following to your index.html: 我建议将以下内容添加到您的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 *">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.