frodo2975
frodo2975

Reputation: 11735

Cordova: How to lock app orientation at boot to landscape and not landscape-reverse?

I'm building a tilt-based game and want to lock the orientation to 1 particular landscape orientation (UIInterfaceOrientationLandscapeRight on iOS). However, if you set the cordova Orientation preference to landscape, it can still rotate 180 degrees to either landscape mode, which isn't acceptable for me. Is this a shortcoming of cordova? I need this, and it's trivial to do natively, so seems like there ought be an easy way to do it.

I'm aware of cordova-plugin-screen-orientation, but it only does stuff once your javascript has started running, which is too late for your splash screen.

Upvotes: 4

Views: 5198

Answers (4)

MDerbyshire
MDerbyshire

Reputation: 39

For anyone coming across this using android, I got it to work (on my phone at least) by adding the below to my config.xml (inside the Widget element)

<preference name="Orientation" value="portrait" />

Upvotes: 1

frodo2975
frodo2975

Reputation: 11735

Found a solution: cordova allows you to edit native attributes through your config.xml file. I feel this ought to be supported natively by cordova itself, but this will work:

<platform name="android">
    <edit-config 
                 file="AndroidManifest.xml"
                 target="/manifest/application/activity[@android:name='MainActivity']"
                 mode="merge"
                 xmlns:android="http://schemas.android.com/apk/res/android">
        <activity android:screenOrientation="landscape"></activity>
    </edit-config>
</platform>

Upvotes: 2

Mingze Li
Mingze Li

Reputation: 390

Currently I am finding the answer for Android and the accepted answer cannot be used now. In Cordova root folder config.xml add:

<platform name="android">
        <preference name="orientation" value="landscape" />
</platform>

Then the app will be landscaped.

Upvotes: 6

Chetan
Chetan

Reputation: 196

Please select landscape and then create build

enter image description here

Upvotes: -2

Related Questions