itake3
January 15, 2015, 12:01am
1
I am trying to figure out how when a device is flipped over.
for an iPhone running iOS8, the window.onorientationchange doesn’t seem to go to 180 (its either 90, 0, or -90).
Do I need to hit the accelerometers directly or is there a way for the phone to tell me?
Any advice?
itake3
January 15, 2015, 12:11am
2
This is what I ended up doing so far for future people:
Using https://github.com/apache/cordova-plugin-device-orientation
with code like this, its able to detect the flipping:
function onSuccess(acceleration) {
document.getElementById("orientation-dg").innerHTML = acceleration.y;
if (acceleration.y > 0)
{
document.getElementById("orientation").innerHTML = '0';
}
else
{
document.getElementById("orientation").innerHTML = '180';
}
};
function onError() {
alert('onError!');
};
var options = { frequency: 500 }; // Update every 3 seconds
var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
Hmm, seems to work for me.
Any way, if you’re going to be using the plugin, you may want to checkout the ng-cordova plugin for it.
http://ngcordova.com/docs/plugins/deviceOrientation/
Is there any example about using ng-cordova device orientation ? i could not get landscape at wp8, the example code from the repository can be used where at the app.js? how to make it act globally into my app ? so any time i change the direction the app will follow.
1 Like