PhoneGap设备准备好不在ios中触发但在android模拟器和涟漪中工作正常

时间:2013-05-02 13:10:07

标签: javascript jquery cordova jquery-mobile cordova-2.0.0

嘿伙计我在ios上启动设备时遇到问题,但代码工作只是在adnroid模拟器上找到并且还涟漪我不知道可能是什么问题。我没有在readl android设备上尝试它,但模拟器工作正常,但我已经尝试在iphone 5上从未调用设备ready.i有另一个问题也是真的有不同平台的cordova有不同的js文件?

var deviceReadyDeferred = $.Deferred();
var jqmReadyDeferred = $.Deferred();

document.addEventListener("deviceReady", deviceReady, false);
document.addEventListener("resume", deviceResume, false);

function deviceResume() {
doWhenBothFrameworksLoaded();
}

function deviceReady() {
deviceReadyDeferred.resolve();
}

$(document).one("mobileinit", function() {
jqmReadyDeferred.resolve();     
});

$.when(deviceReadyDeferred, jqmReadyDeferred).then(
doWhenBothFrameworksLoaded);

function doWhenBothFrameworksLoaded() {
var networkState = navigator.connection.type;

var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';

if (networkState == Connection.NONE)
    alert('You have to be connected to the internet in order to use this app.');
else {
    setTimeout(function(){
        $.mobile.changePage("deals.html", {
            transition : "pop",
            reverse : false,
            changeHash : false
        });
    },1000);
}
}


<!DOCTYPE HTML>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>PhoneGap</title>

    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script type="text/javascript" charset="utf-8" src="cordova-2.6.0.js"></script>
    <script type="text/javascript" charset="utf-8" src="PushNotification.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jquery.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="controller/index.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jqueryMobile.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/handlebars.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/handleHelpers.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jquery.timeago.js"></script>


    <link rel="stylesheet" href="css/jqm.css" charset="utf-8" />
    <link rel="stylesheet" href="css/style.css" charset="utf-8" />
</head>
<body>
    <div class="container splash" data-role="page" id="index">
        <img src="img/logo.png" />
    </div>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

为了使用phonegap和jquery mobile,你需要像这样使用它,

$(document).one("mobileinit", function() {
    $.support.cors = true;
    $.mobile.allowCrossDomainPages = true;
    jqmReadyDeferred.resolve();     
});

答案 1 :(得分:0)

原来我必须从目录中删除cordova js文件,并在config.xml上为phonegap构建指定。谢谢大家