0

嘿,伙计们,我在 ios 上启动 deviceready 时遇到问题,但代码工作只能在 adnroid 模拟器上找到,而且我不知道可能是什么问题。我没有在 readl android 设备上尝试过,但模拟器工作正常,但我在 iphone 5 上尝试过它从来没有调用设备准备好。我还有另一个问题,对于不同的平台,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>
4

2 回答 2

0

为了将 phonegap 与 jquery mobile 一起使用,您需要像这样使用它,

$(document).one("mobileinit", function() {
    $.support.cors = true;
    $.mobile.allowCrossDomainPages = true;
    jqmReadyDeferred.resolve();     
});
于 2013-05-02T13:50:43.003 回答
0

事实证明,我必须从目录中删除 cordova js 文件,并在 config.xml 上为 phonegap build 指定该文件。谢谢大家

于 2013-05-03T10:29:37.923 回答