[英]device.platform return 'device is not defined' on cordova project
I've a problem that happens randomly when I run my cordova android application. 我运行Cordova Android应用程序时会随机发生一个问题。 Basically the "device" sometime is null and sometime not.
基本上,“设备”有时为null,有时不是。 I dunno why it happens, this is the first portion of my code:
我不知道为什么会这样,这是我的代码的第一部分:
app.js app.js
app = {
// deviceready Event Handler
onDeviceReady: function() {
try
{
var devicePlatform = device.platform;
var deviceVersion = device.version;
}
catch(e)
{
alert("Error: "+e)
}
....
}
}
index.html index.html
....
</div>
<script src="cordova.js"></script>
<script src="js/libs/openfb.js"></script>
<script src="js/app.js"></script>
<script>
$(document).on("mobileinit", function() {
$.mobile.ajaxEnabled = true;
$.mobile.linkBindingEnabled = true;
$.mobile.defaultPageTransition = "fade";
$.mobile.phonegapNavigationEnabled = true;
$.mobile.allowCrossDomainPages = true;
});
// init application
$(window).load(function() {
$(document).bind('deviceready', app.onDeviceReady());
});
</script>
</body>
</html>
The device plugin was outdated so I obtained the new version, 0.3.0 but the bug is still there. 设备插件已过时,因此我获得了新版本0.3.0,但该错误仍然存在。 Any hints?
有什么提示吗?
Your app should work on real phone, not on emulator. 您的应用应该可以在真实手机上运行,而不是在模拟器上运行。
Please try binding a listener 请尝试绑定监听器
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var element = document.getElementById('deviceProperties');
element.innerHTML = 'Device Model: ' + device.model + '<br />' +
'Device Cordova: ' + device.cordova + '<br />' +
'Device Platform: ' + device.platform + '<br />' +
'Device UUID: ' + device.uuid + '<br />' +
'Device Version: ' + device.version + '<br />';
}
See more at PhoneGap API 在PhoneGap API上查看更多
Hope this helps ! 希望这可以帮助 !
Cheers ! 干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.