【发布时间】:2016-03-29 12:19:32
【问题描述】:
我无法让我的图像在我的 phonegap 版本中工作。
我读到绝对路径可能不起作用,所以我尝试了绝对路径和相对路径,仍然没有运气。
我包括这样的图像:
<Col key={1} xs={3}>
<Image src='/tire_selected.png' responsive />
</Col>
或相对
<Col key={1} xs={3}>
<Image src='tire_selected.png' responsive />
</Col>
等于
<img class="img-responsive" src="tire_deselected.png" data-reactid=".0.0.1.0.0.0.0.1.1.0.0.$4.0">
Col & Image 是使用 bootstrap-react 的引导辅助组件。这一切在 web 视图中都可以正常工作,但在使用 phonegap 构建时就不行了。不过,源代码应该已经编译并且在这两种情况下都没有错误。
以下是我的 config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.app.exampleapp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>App</name>
<description>
App
</description>
<author email="support@example.com" href="http://www.example.com">
Author
</author>
<content src="index.html" />
<preference name="permissions" value="none" />
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<preference name="prerendered-icon" value="true" />
<preference name="stay-in-webview" value="false" />
<preference name="ios-statusbarstyle" value="black-opaque" />
<preference name="detect-data-types" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="auto-hide-splash-screen" value="true" />
<preference name="disable-cursor" value="false" />
<preference name="android-minSdkVersion" value="14" />
<preference name="android-installLocation" value="auto" />
<gap:plugin name="org.apache.cordova.geolocation" />
<icon src="icon.png" />
<access origin="*" />
<plugin name="cordova-plugin-whitelist" version="1" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
Git 仓库:
app.js
vendor.js
config.xml
favicon.ico
humans.txt
index.html
robots.txt
tire_deselected.png
tire_selected.png
Icon.png 工作正常。我不知道是什么导致其他图像不起作用。任何帮助将不胜感激!
编辑
我已经尝试设置 content-security-policy,如果这是我无法设置 img-src 并通过 javascript 显示图像的问题。
<meta http-equiv="Content-Security-Policy" content="
default-src http://10.3.10.104/ 'self' * 'unsafe-inline';
style-src http://10.3.10.104/ 'self' * 'unsafe-inline';
img-src http://10.3.10.104/ 'self' * 'unsafe-inline';
script-src http://10.3.10.104/ 'self' * 'unsafe-inline';">
但还是没有运气
file:///tire_deselected.png net::ERR_FILE_NOT_FOUND
那里有文件,因为在将 img-element 插入 index.html 时它会显示出来。
我什至尝试通过运行开发者工具的源文件夹中显示的路径来访问它。
file:///data/user/0/com.oas.exampleapp/files/downloads/app_dir/tire_deselected.png
也不行,我开始认为phonegap坏了,至少与react结合起来效果很差。
【问题讨论】:
-
我添加了引导标签。这似乎与 Phonegap 无关。
-
怎么样?除了 phonegap 构建应用程序时,图像在任何地方都可以正常工作。问题与引导无关。
-
不同意。这不是电话间隙问题。如果您删除引导程序并使用标准 HTML,则会显示图像。唯一的例外*可能*是图像存储在设备之外 - 事实并非如此。既然你认为自己更聪明 - 祝你好运。
-
HTML 是标准的 HTML,它是经过编译的。如果不清楚,我很抱歉。但是你应该知道,如果你从 git repo 构建了一个 phonegap 应用程序。
-
给我20分钟
标签: image reactjs phonegap-build