Reputation: 3315
I want my app to always be in portrait so in config.xml file I have this line.
<preference name="Orientation" value="portrait"/>
Which works just fine.
The problem is I can't detect screen orientation after that.
I tried with
function doOnOrientationChange() {
console.log(window.orientation);
}
window.addEventListener('orientationchange', doOnOrientationChange);
doOnOrientationChange();
This code shows me 0
when my phone is in portrait and 180
when it is upside-down BUT nothing when in landscape (not 90
nor -90
).
I saw this plugin https://github.com/gbenvenuti/cordova-plugin-screen-orientation which seems to be used by a lot of people, but I can't make it to work on my iPhone 6S (iOS9), after looking at the issues, it seems that I'm not the only one...
Right now I don't know where to go so any kind of help would be much appreciated!
Upvotes: 1
Views: 2621
Reputation: 3315
I've not tested it yet but I've just came across the Screen Orientation plugin (from Cordova) and that was exactly what I was looking for.
Thanks everybody for the help!
Upvotes: 1
Reputation: 3039
The problem is that those functions or plugins, are returning the SCREEN orientation, not the DEVICE orientation. That is why you only get 0 or 180. Probably you need to use this plugin, which reads the device compass, so you can get what you want
https://github.com/apache/cordova-plugin-device-orientation
Happy coding!
Upvotes: 0