1

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!

2
  • In iOS9 they have restricted so many functionalities to work for security reasons, you have to update your info.plist file with some attributes for screen orientation plugin to work
    – Anil kumar
    Commented Mar 16, 2016 at 14:06
  • Thanks for your answer, do you have any additional informations about those attributes?
    – Elie Faës
    Commented Mar 16, 2016 at 14:16

2 Answers 2

1

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!

0

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!

1
  • Yeah had a thought about that, but seems really overkill to use a compass or accelerometers just to know if the user turned his phone I can't believe that this is the best solution...
    – Elie Faës
    Commented Mar 16, 2016 at 16:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.