Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Newsroom Update

Apple is introducing a new Apple Watch Pride Edition Braided Solo Loop, matching watch face, and dynamic iOS and iPadOS wallpapers as a way to champion global movements to protect and advance equality for LGBTQ+ communities. Learn more >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

DeviceOrientationEvent in Safari (iPhone 3GS, iOS 4.2)

I'm trying to get orientation and accelaration information with Javascript. Safari with iOS 4.2 at iPhone 3GS and iPhone 4 should support both device motion and orientation APIs. However, it seems DeviceOrienationEvent is not working in Safari at iPhone 3GS + iOS 4.2. In javascript,

window.DeviceMotionEvent
window.DeviceOrientationEvent

both of these are defined, so I expect event listeners for them to work but,

window.addEventListener( "devicemotion", function( event ){ ...
window.addEventListener( "deviceorientation", function( event ) { ...

for devicemotion, this event listener works good, but not deviceorientation.

I've checked with iPhone4, and it works just fine. Both device motion listener and device orientation listener work, but not iPhone 3GS.

Is this a bug in Safari or iOS 4.2? Any idea?

Thanks.

iPhone 3G S, iOS 4

Posted on Dec 23, 2010 7:26 PM

Reply
1 reply

Mar 17, 2011 12:59 AM in response to honestjung

Even if you can subscribe to whatever event you want in the browser, you will only receive only those the browser can send.
To get deviceorientation events you need a gyroscope, which iphone4 and ipad2 have but not iphon3GS or ipad.

If you go to DeviceOrientationEvent class reference ( http://developer.apple.com/library/safari/#documentation/SafariDOMAdditions/Refe rence/DeviceOrientationEventClassRef/DeviceOrientationEvent/DeviceOrientationEve nt.html#//apple_ref/doc/uid/TP40010526), you can read that "Instances of DeviceOrientationEvent are fired only when the device has a gyroscope and while the user is changing the orientation."

If you use devicemotion, you will not be able to get the acceleration property if your device doesn't have a gyroscope. In that case, you will have to get accelerationIncludingGravity

P.s: Sorry to get a thread from some months ago but in Spanish we say "It's better late than never" and I considered this quite useful

Message was edited by: redjhawk

DeviceOrientationEvent in Safari (iPhone 3GS, iOS 4.2)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.