Javascript. Listen for iPhone shake event?

余生颓废 提交于 2019-12-05 03:29:10

Not as a straight web app, no. If you wrap your web app in PhoneGap, it exposes accelerometer and other app-only features to the site running within it, but the downside is that people have to actually download your app - they can't just browse to a site in Safari.

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

Mr Speaker

Here's an elegant implementation of shake detection using the accelerometer if anyone is looking for it:

https://github.com/alexgibson/shake.js

Mat

I just implemented the above in my web app which now has controls that appear on the page only after a device shake occurs. Very easy to implement and cleanly described.

https://github.com/alexgibson/shake.js

It is also worth noting that the iOS simulator's shake gesture doesn't trigger the event but a genuine device shake does.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!