嘿,伙计们,我在 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>