2013-01-14 61 views
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
  1. 我不知道,如果是你的問題,但你必須小姐在你的身體結束時關閉標籤,它看起來像 </body.

  2. 確保您有這行config.xml文件:

    <plugin name="Accelerometer" value="CDVAccelerometer" />

  3. 是還有其他的phonegap功能,比如navigator.notification.alert工作得很好嗎?也許你的項目設置不正確?

  4. 確保cordova-2.3.0.js適用於iOS版本。

+0

1. XCode中的body標籤很好。格式似乎搞亂了stackoverflow 2.什麼行? 3.項目設置正確。我能夠獲得默認代碼並正確運行。 4.我不明白這一點很好 –

+0

再次檢查我的答案2,編輯。 –

+0

是的,那是 –

相關問題