I hope this is not too late, but it is not surprising that Safari for iOS 4.2+ will register DeviceOrientationEvent on iPhone 3GS (or other devices without a gyroscope)?
Bottom Line, DeviceOrientation does not work with iPhone 3GS. But, as already mentioned, DeviceMotionEvent works, but you need to access the event data in a different way than with a device with a gyroscope (I know stupid!).
First step: I added a variable to the mix to capture whether the OrientationEvent really triggers any non-zero data (as if it were a gyroscope).
var canHandleOrientation; if (window.DeviceOrientationEvent) { window.addEventListener("deviceorientation", handleOrientation, false); } function handleOrientation(event){ console.log("Orientation:" + event.alpha + ", " + event.beta + ", " + event.gamma); canHandleOrientation = event;
Now you know if the event really has gyro data or not! Therefore, if you want something else by default (i.e. window.DeviceMotionEvent), you can use a conditional expression.
if (!canHandleOrientation) { console.log("There is no gyroscope") }
I tested this on Mobile Safari for iPhone 3GS (without a gyro) and iPad 2 (gyro) and Chrome on my Macbook Pro (gyro). Seems to work.
Now, if you want to get DeviceMotionEvent data as an alternative, if Orientation data is not available, then ...
if (window.DeviceMotionEvent && !canHandleOrientation) { window.addEventListener('devicemotion', handleMotion, false); } function handleMotion(event){ if(event.acceleration){ //requires a gyroscope to work. console.log("Motion Acceleration: " + event.acceleration.x + ", " + event.acceleration.y + ", " + event.acceleration.z); } else{ //this is for iPhone 3GS or a device with no gyroscope, and includes gravity. console.log("Motion AccelerationGravity: " + event.accelerationIncludingGravity.x + ", " + event.accelerationIncludingGravity.y + ", " + event.accelerationIncludingGravity.z); } }
This should cover your databases for most devices using the webkit browser ... I hope so. Havent tested it on any Android device.
It should be noted that each event returns different numbers, so you may need to do some work to normalize them. But these are the basics of how you address them.
Let me know if this helps!