2015-12-07 61 views
2

我有一个cordova项目,我需要使用inappbrowser插件打开一个窗口,里面有一个cordova页面,而“parent”仍然运行。Cordova inappbrowser deviceready never fires

Cordova负载index.html它使用inappbrowser插件打开frame.html
科尔多瓦得到的加载到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-filecordova-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="[email protected]" 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插件,因为bluetoothle插件必须在通过另一个框架中的应用程序导航时保持连接。 这些框架还需要能够与海誓山盟进行沟通,并且都可以访问cordova库。

如果有人有其他想法如何做到这一点,我为他们开放。

更新:

我寻找到cl.kunder。网页流量https://github.com/kunder-lab/cl.kunder.webview插件

+0

“deviceready”将调用只有一次,当您的index.html负荷首次。如果你想用你的InAppBrowser加载事件,我想你需要使用InAppBrowser事件,比如“loadstart,loadstop,loaderror,exit”。 不知道这是你寻找的解决方案,但据我了解这是你想要的。 – JDev

+0

@JDev科尔多瓦记录2个频道没有开火。如果我删除使用这两个通道的插件,则设备准备就会**。我希望它与安装的插件一起启动。这2个插件还没有完成加载,否则设备准备好会触发 – x13

回答

1

@ThisNameBetterBeAvailable,

没有科尔多瓦服务提供给InAppBrowser

从文档(第3号)我引用

的InAppBrowser窗口的行为就像一个标准的Web浏览器,而不能访问科尔多瓦的API。

这意味着没有插件,没有事件,没有任何服务。我试图让他们修复这部分文档,但这将是一段时间。

你可以在这里看到:https://issues.apache.org/jira/browse/CB-9470

+0

而且我认为添加这些cordova API本身太难了? 或者是分叉它并添加cordova API的可能吗? – x13

+0

我以前使用过的[插件](https://github.com/cvuser0/cl.kunder.webview)似乎能够访问cordova API,但只有我无法在创建的webview和发起它的webview。 – x13

+0

感谢插件上的指针。截至目前,Cordova Plugin Repsository中有13个[webview选项](http://cordova.apache.org/plugins/?q=webview);许多是一个或两个基本来源的克隆。我试图保留一个正式运行的博客[webview](https://github.com/jessemonroy650/top-phonegap-mistakes/blob/master/webview.md)库,它们的[details](https:// github.com/jessemonroy650/top-phonegap-mistakes/blob/master/webview-details.md)和[alternatives](https://github.com/jessemonroy650/top-phonegap-mistakes/blob/master/webview-alternatives .MD)。 – JesseMonroy650

相关问题