Phonegap deviceready不使用Cordova 2.2.0在iOS中 [英] Phonegap deviceready not firing using Cordova 2.2.0 in iOS

查看:234
本文介绍了Phonegap deviceready不使用Cordova 2.2.0在iOS中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个PhoneGap应用程式。不幸的是,当部署到iOS设备和模拟器时, deviceready 事件不会触发。我使用Phonegap 2.2.0。



当我部署相同的代码到Android(使用Android特定 cordova.js

当我用一个jQuery替换 deviceready - ready()该应用程序也将加载到iOS上,但是它将无法访问设备特定的API。



cordova.js 已加载,因为我会看到一个简单的警告消息,我把它放在它,而 deviceready

我的HTML

 < script type =text / javascriptcharset =utf-8src =js / cordova.js>< / script& <! - 是的是iOS版本 - > 
< script src =js / jquery-1.8.2.min.js>< / script>
< script src =js / app.js>< / script>

我的JS:

  function doStuff(){
// app functionality
}
document.addEventListener('deviceready',doStuff,false);

但是不知何故,东西只能在Android上完成...


<我有一个onload触发添加事件监听器到deviceready

 >  function onDeviceReady(){
console.log(we are an app);
MyApp.initialize_phonegap();
}

function onBodyLoad(){
document.addEventListener(deviceready,onDeviceReady,false);
}

< / script>

< / head>

< body onload =onBodyLoad()>


I am building a PhoneGap App. Unfortunately, when deploying to iOS devices and simulators the deviceready event never fires. I'm using Phonegap 2.2.0.

When I deploy the same code to Android (using the Android-specific cordova.js file of course) the App will work perfectly.

When I replace the deviceready with a jQuery-ready() the app will load on iOS as well, yet it will then lack access to the device specific APIs.

The cordova.js is loaded as I will see a simple alert message that I put inside of it, yet deviceready never fires and the APIs are never exposed.

My HTMLs head:

<script type="text/javascript" charset="utf-8" src="js/cordova.js"></script> <!-- yes it is the iOS version -->
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/app.js"></script>

My JS:

function doStuff(){
//app functionality
}
document.addEventListener('deviceready', doStuff, false);

But somehow stuff will only get done on Android...

解决方案

in my html I have a onload that triggers that adding of an event listener to deviceready

      function onDeviceReady() {
        console.log("we are an app");
        MyApp.initialize_phonegap();
      }

      function onBodyLoad() {   
        document.addEventListener("deviceready", onDeviceReady, false);
      }

    </script>

  </head>

  <body onload="onBodyLoad()">

这篇关于Phonegap deviceready不使用Cordova 2.2.0在iOS中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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