iOS - deviceready 5秒钟后没有触发 [英] iOS - deviceready has not fired after 5 seconds

查看:1117
本文介绍了iOS - deviceready 5秒钟后没有触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

deviceready 在第二页上不再触发。
假设我有:



page1.html - 输入页。





page2.html - 另一页。



在page1中,我有以下代码:

  document.addEventListener(deviceready onDeviceReadyPopup,false); 

function onDeviceReadyPopup(){
window.location.href =page2.html;
}

在第2页,我有以下代码:

  document.addEventListener(deviceready,onDeviceReady,true); 

function onDeviceReady(){
alert(Script - Device ready!问题:警告从未触发,因为它不会触发<$ c








$ b c> deviceready
事件。这将在 android 中正常工作。



我怀疑这是因为我使用 window.location.href

解决方案

deviceready 每个应用程序生命周期一次。



此事件对任何应用程序都是必不可少的。它表示Cordova的设备API已加载并可以访问。



Cordova包含两个代码库:native和JavaScript。在加载本机代码时,会显示自定义加载图像。



但是,JavaScript只会在DOM加载时加载。这意味着在相应的本地代码可用之前,网络应用程序可能会调用Cordova JavaScript函数。



一旦Cordova完全加载,deviceready事件就会触发。



了解详情: http://cordova.apache.org/docs/en/3.5.0/cordova_events_events.md.html#deviceready


deviceready was no longer fired on second page. Let's say I have:

page1.html - entry page.

and

page2.html - another page.

In page1, I have this code:

document.addEventListener("deviceready", onDeviceReadyPopup, false);

function onDeviceReadyPopup(){
    window.location.href="page2.html";
}

In page2, I have this code:

document.addEventListener("deviceready", onDeviceReady, true);      

function onDeviceReady() {
     alert("Script - Device ready!");
} 

Problem: alert was never fired since it does not fire the deviceready event. This will just work fine in android.

I doubt that it is because I am using window.location.href?

解决方案

deviceready event fires only once per application lifecycle.

This event is essential to any application. It signals that Cordova's device APIs have loaded and are ready to access.

Cordova consists of two code bases: native and JavaScript. While the native code loads, a custom loading image displays.

However, JavaScript only loads once the DOM loads. This means the web app may potentially call a Cordova JavaScript function before the corresponding native code becomes available.

The deviceready event fires once Cordova has fully loaded.

for more: http://cordova.apache.org/docs/en/3.5.0/cordova_events_events.md.html#deviceready

这篇关于iOS - deviceready 5秒钟后没有触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆