我试图在Android上设置Phonegap并且deviceready不会触发.原因是DeviceInfo.uuid始终为null/undefined.
看起来像phonegap的非javascript部分没有正确加载,但我看不清楚到底是什么.对于www目录之外的所有内容,我正在使用phonegap下载示例目录中提供的代码.
有谁知道可能导致这种情况的原因?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" charset="utf-8" src="javascripts/phonegap-1.0.0.js"></script>
<script src="http://debug.phonegap.com/target/target-script-min.js#something"></script>
<script type="text/javascript" charset="utf-8">
function onBodyLoad() {
var initialize = function() {
window.console.log("deviceready||resume");
};
document.addEventListener("deviceready", initialize);
document.addEventListener("resume", initialize);
window.console.log("onBodyLoad!");
}
</script>
</head>
<body onload="onBodyLoad()">
<h1>Herro World</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
san*_*rom 31
万一其他人偶然发现了这个问题.
我没有意识到iPhone和Android版本的phonegap-1.0.0.js是不同的.它具有相同的名称,但内容不同.因此,必须加载正确的文件.我这样解决了:
<script type="text/javascript">
// Atrocious way of loading two diffent phonegap scripts, but other loading methods won't work.
// also there shouldn't be two scripts to begin with -- so much for cross-platform.
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.match(/android/)) {
document.write("<script type='text/javascript' src='javascripts\/phonegap-android-1.0.0.js'><\/script>");
} else {
document.write("<script type='text/javascript' src='javascripts\/phonegap-iphone-1.0.0.js'><\/script>");
}
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7063 次 |
| 最近记录: |