[英]“deviceready has not fired after 5 seconds” cordova 3.5.0-0.2.1
[英]Cordova: always deviceready has not fired
我對Cordova還有另一個問題。 我想在Cordova 7.1.0中使用插件“ cordova.custom.plugins.exitapp”和“ cordova-plugins-printer”。
在服務器端,我已經將document.AddEventListener內置到$(document).ready(function() {});
.js文件:
$(document).ready(function(){
...
document.addEventListener("deviceready", exitFromApp, false);
...
}),
function exitFromApp() {
console.log("NAVIGATOR: " + navigator);
console.log("NAVIGATOR.APP: " + navigator.app);
console.log("NAVIGATOR.APP.EXITAPP: " + navigator.app.exitApp());
navigator.app.exitApp();
}
無論我是否使用addEventListener,Android Studio始終會說:
-5秒鍾后未啟動deviceready。
-頻道未觸發:onPluginsReady
-頻道未觸發:onCordovaReady
但是區別在於addEventListener
不會調用exitFromApp()
函數。
當我直接調用exitFromApp()
,它可以工作,但是navigator.app是未定義的(或者cordova.plugins / window.plugins是未定義的)。
cordova.js在header.php中被調用,因此始終可用。
如果我通過平板電腦上的index.html使用插件,則可以使用。
我已經在config.xml中設置了權限:
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="*" />
安裝:
科爾多瓦7.1.0
cordova-plugin-inappbrowser 2.0.1
科爾多瓦插件網絡信息2.0.1
科爾多瓦插件白名單1.3.3
cordova.custom.plugin.exitapp 1.0.0
phonegap.plugin-barcodescanner 7.0.1
科爾多瓦插件打印機0.7.3
$(document).ready()
之前會觸發deviceready
事件。在兩個都被激發之后,您想做些什么。
var DomReady = new Promise(done=>$(document).ready(done));
var deviceReady = new Promise(done=>document.addEventListener("deviceready", done, false));
Promise.all[DomReady, deviceReady].then(()=>{
// both device and dom are ready
});
...或者您也可以將deviceReady調用放在未准備就緒的調用之外,因為我確定始終將設備就緒放在第一位。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.