【发布时间】:2015-12-07 13:29:43
【问题描述】:
我有一个 cordova 项目,我需要使用 inappbrowser 插件打开一个窗口,其中包含一个 Cordova 页面,而“父级”仍在运行。
Cordova 使用 inappbrowser 插件加载 index.html,打开 frame.html。
Cordova 已加载到 frame.html,但 deviceready 事件从未触发,5 秒后我在 frame.html 的控制台中收到此错误。
这只发生在使用 inappbrowser 插件打开的第二个 webview 中。
错误:
cordova.js:1183 deviceready has not fired after 5 seconds.
cordova.js:1176 Channel not fired: onFileSystemPathsReady
cordova.js:1176 Channel not fired: onCordovaInfoReady
我进行了很多搜索,得出的结论是,并不是文档的 onload 中的插件或代码过多会延迟触发 deviceready 所需的 onNativeReady 事件。
当我删除 cordova-plugin-file 和 cordova-plugin-file-transfer 时,onFileSystemPathsReady 错误消失了。
如果我删除 cordova-plugin-device,onCordovaInfoReady 错误就会消失。
但我需要那些插件。
是什么导致 deviceready 事件根本不触发?
在不删除我需要的插件的情况下,我该怎么做才能让它启动?
项目信息:
Node version: v4.2.2
Cordova version: 5.4.1
Installed platforms:
android 4.1.1
ios 3.9.2
Installed plugins:
cordova-plugin-bluetoothle 2.4.0 "Bluetooth LE"
cordova-plugin-device 1.1.0 "Device"
cordova-plugin-dialogs 1.2.0 "Notification"
cordova-plugin-file 3.0.0 "File"
cordova-plugin-file-transfer 1.4.0 "File Transfer"
cordova-plugin-inappbrowser 1.1.0 "InAppBrowser"
cordova-plugin-vibration 2.0.0 "Vibration"
cordova-plugin-whitelist 1.2.0 "Whitelist"
de.appplant.cordova.plugin.background-mode 0.6.4 "BackgroundMode"
Config.xml file:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.test.app" version="0.0.1" xmlns="http://www.w3.org/ns/widgets">
<name>TestApp</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-navigation href="http://*/*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
index.html:
<!DOCTYPE html>
<html >
<head >
<meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline';" >
<meta name="format-detection" content="telephone=no" >
<meta name="msapplication-tap-highlight" content="no" >
<meta name="viewport" content="user-scalable=no, initial-scale=1, height=device-height, width=device-width" >
<title >Index</title >
<script >
document.addEventListener( 'deviceready', function ()
{
console.log( 'ready' );
win = window.open( 'frame.html', '_blank', 'location=no', function()
{
console.log( arguments );
} );
}, false );
</script >
</head >
<body >
<script type="text/javascript" src="cordova.js" ></script >
</body >
</html >
frame.html:
<!DOCTYPE html>
<html >
<head >
<meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline';" >
<meta name="format-detection" content="telephone=no" >
<meta name="msapplication-tap-highlight" content="no" >
<meta name="viewport" content="user-scalable=no, initial-scale=1, height=device-height, width=device-width" >
<title >Frame</title >
<script >
window.addEventListener( 'deviceready', function()
{
console.log( 'window.deviceready', arguments );
}, false );
document.addEventListener( 'deviceready', function()
{
console.log( 'document.deviceready', arguments );
}, false );
</script >
</head >
<body >
<script type="text/javascript" src="cordova.js" ></script >
</body >
</html >
更新:
我正在使用两个自我修改的插件(不是导致问题的插件),也许这是某种相关的:
编辑:
我需要使用 inappbrowser 插件,因为蓝牙插件必须在另一个框架中浏览应用程序时保持连接。 框架还需要能够相互通信,并且都可以访问cordova库。
如果有人有其他想法如何做到这一点,我愿意接受。
更新:
我正在研究 cl.kunder.webviewhttps://github.com/kunder-lab/cl.kunder.webview 插件
【问题讨论】:
-
"deviceready" 只会在您的 index.html 首次加载时调用一次。如果您想使用 InAppBrowser 加载事件,我想您需要使用 InAppBrowser 事件,例如“loadstart、loadstop、loaderror、exit”。不确定这是您正在寻找的解决方案,但据我了解,这就是您想要的。
-
@JDev cordova 记录了 2 个通道尚未触发。如果我删除使用这 2 个通道的插件,设备就绪 将 触发。我希望它在安装插件的情况下触发。这 2 个插件还没有完成加载,否则 deviceready 会触发
标签: javascript cordova