本文介绍了Cordova'deviceready'事件在wp8上触发两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在科尔多瓦开发WP8应用程序.

I'm developing a WP8 application in Cordova.

我已经在Android和iOS上完成了该应用程序,但是在WP8上,"deviceready"事件触发了两次? :(

I already finished the app in Android and iOS, but on WP8 the 'deviceready' event is firing twice? :(

  • 我试图添加一个计数器以准备就绪,但计数器每次都从0开始
  • 我用var r = false尝试过,如果将ready设置为true,请尝试.但是r保持错误
  • 我什至尝试使用随机数学准备好计时器.还是没事

仍然执行两次

document.body.onload = onLoad;

function onLoad() {
    console.log('onload');
    document.addEventListener('deviceready', ready, false);
}

function ready(){
    console.log('ready'); //firing twice
}

已安装以下cordova插件:

The following cordova plugins are installed:

  • 2.4.0"PushPlugin"
  • 1.0.0控制台"
  • 2.4.0"PushPlugin"
  • 1.0.0控制台"
  • 1.0.0设备"
  • 1.0.0通知"
  • 1.0.0地理位置"
  • 1.0.0全球化"
  • 1.0.0"InAppBrowser"
  • 1.0.0网络信息"
  • 1.0.0白名单"
  • 1.2.0"UniqueDeviceID"
  • 3.2.2自定义URL方案"
  • 1.0.0启动画面"
  • 0.3.13振动"
  • 0.1.7"AppVersion"
  • 2.4.0 "PushPlugin"
  • 1.0.0 "Console"
  • 2.4.0 "PushPlugin"
  • 1.0.0 "Console"
  • 1.0.0 "Device"
  • 1.0.0 "Notification"
  • 1.0.0 "Geolocation"
  • 1.0.0 "Globalization"
  • 1.0.0 "InAppBrowser"
  • 1.0.0 "Network Information"
  • 1.0.0 "Whitelist"
  • 1.2.0 "UniqueDeviceID"
  • 3.2.2 "Custom URL scheme"
  • 1.0.0 "Splashscreen"
  • 0.3.13 "Vibration"
  • 0.1.7 "AppVersion"

希望你们能帮助我,因为我不知道.

Hope you guys can help me because I can't figure it out.

如果有人需要更多信息,请问我:)

If someone needs more information, just ask me :)

谢谢!

推荐答案

如果将 console.log 更改为警报,那么您将看到设备已就绪触发一次... Windows Phone的控制台插件仅重复复制消息,尝试删除该插件,您将看到一条消息就绪" ...

If you change console.log to alert then you will see that deviceready fired once... Console plugin for windows phone just doing duplicate of messages, try remove the plugin and you will see one message "ready"...

这篇关于Cordova'deviceready'事件在wp8上触发两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 07:12