2
我正在使用iOS的Phonegap构建我的第一个应用程序。我正在尝试获取加速度计值并将其作为警报显示在屏幕上。我有最新版本的cordova-2.3.0。以下是index.html文件的代码 -Phonegap - 第一个应用程序
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Device Ready Example</title>
<script type=”text/javascript” charset=”utf-8” src=”cordova-2.3.0.js”></script>
<script type=”text/javascript” charset=”utf-8”>
document.addEventListener(“deviceready”, onDeviceReady, false);
function onDeviceReady() {
navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
}
// onSuccess: Get a snapshot of the current acceleration
//
function onSuccess(acceleration) {
alert('Acceleration X: ' + acceleration.x + '\n' +
'Acceleration Y: ' + acceleration.y + '\n' +
'Acceleration Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
}
// onError: Failed to get the acceleration
//
function onError() {
alert('onError!');
}
</script>
</head>
<body>
<h1> Example </h1>
<p>getCurrentAcceleration </p>
</body
</html>
但是,没有任何反应。我用白色屏幕写了Example和getCurrentAcceleration。
有人可以帮忙吗?
感谢
1. XCode中的body标签很好。格式似乎搞乱了stackoverflow 2.什么行? 3.项目设置正确。我能够获得默认代码并正确运行。 4.我不明白这一点很好 –
再次检查我的答案2,编辑。 –
是的,那是 –