Is there access to the iPhone accelerometer using Javascript?

前端 未结 5 384
心在旅途
心在旅途 2021-01-01 23:21

I\'m starting to try and do some web based game programming for my iPhone, and other web enabled phones that my friends have, and was having a hard time finding information

相关标签:
5条回答
  • 2021-01-01 23:22

    If your are using iOS 4.2 or more, then you can do it: http://www.albertosarullo.com/blog/javascript-accelerometer-demo-source

    0 讨论(0)
  • 2021-01-01 23:27

    In the latest iOS update (4.2) the accelorometer is now accessible from Javascript.

    See: http://www.mobilexweb.com/blog/safari-ios-accelerometer-websockets-html5

    0 讨论(0)
  • 2021-01-01 23:27

    jharlap is correct, however I'd be curious to know if this would work on the Palm Pre. Native development on the Pre is done using html and JavaScript, however there are special JavaScript APIs to access the phone's features that I believe only work for locally stored apps. I wonder if these are available through the browser. I doubt it, but it would be interesting.

    0 讨论(0)
  • 2021-01-01 23:27

    Checkout PhoneGap project. It provides API to access the accelerometer and the GPS location from javascript.

    "Regular" javascript cannot access the accelerometer info, it can access the geolocation using the W3C geolocation API supported by iPhone OS 3.0.

    Yet, a project (e.g. PhoneGap) can be used to build a bridge between javascript and Objective-C capabilities to expose that functionality. This works if you want to deploy the app as a standalone application, that simply has one WebKit which loads the html content from the server.

    I haven't played with their framework, but they provide templates for the iPhone and Android projects and you can work on developing your javascript game which would work almost-out-of-the-box on iPhone and Android. I cannot comment on the performance and the user experience though.

    0 讨论(0)
  • 2021-01-01 23:35

    iOS 4.2 provides Accelerometer & Gyroscope support through the DeviceOrientation API.

    • DeviceMotionEvent class reference

    • DeviceOrientationEvent class reference

    Here a working javascript snippet.

    0 讨论(0)
提交回复
热议问题