2015-12-07 72 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

相關問題