Kiiti
Kiiti

Reputation: 71

cordova - How to disable orientation upside down for ios?

In my app(ionic + cordova) i set orientation for portrait, but when i open xcode to build, the option updside down is enable. how can i disable upside down in my config.xml?

my config.xml

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

thank you

Upvotes: 7

Views: 3953

Answers (5)

Jonathan Sanchez
Jonathan Sanchez

Reputation: 9354

So it's a combination of the config.xml file and XCODE settings.

In the config.xml file you'll need to add the following line right before the closing </widget> tag

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

enter image description here

Then inside of Xcode need to disable the Upside Down option under the Device Orientation settings.

enter image description here

Then you will have to delete the platforms directory then rebuild the apps so that the change will take.

Upvotes: 2

Muhammad Mehdi Raza
Muhammad Mehdi Raza

Reputation: 591

The only and better way to do that is, simply install cordova-plugin-screen-orientation plugin in your project. And in the ionic.Platform.ready(function() {}) use the following code:

if (window.cordova && cordova.plugins) {
    cordova.plugins.screenorientation.setOrientation('portrait-primary');
}

I also had the same issue, which was causing iPhone SE to change orientation upside-down, and this code fixed it for me.

Upvotes: 0

Naderio
Naderio

Reputation: 1419

I found a solution that is working for my projects. With the installed Cordova plugin cordova-custom-config you can overwrite the UISupportedInterfaceOrientations-Setting with the following code inside of the <platform name="ios">:

<custom-config-file mode="replace" parent="UISupportedInterfaceOrientations" platform="ios" target="*-Info.plist">
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
</custom-config-file>

Important is the parameter mode="replace" The Key is of type Array and will be merged by default.

Outside the platform-tags you can set the default <preference name="orientation" value="portrait" />. This will be used for Android and woont allow upside down there.

Upvotes: 0

Sonic Wong
Sonic Wong

Reputation: 1

You can't untick iOS "up-side-down" by config file.

But you can use screen-orientation plugin to control it. (website)

Upvotes: 0

Desmond Jones
Desmond Jones

Reputation: 34

Try changing your config.xml to: <preference name="orientation" value="default" />

Then at the platform level for iOS change your preference value to "portrait" via: <preference name="orientation" value="default" />

Config Ref

Default: default

Allowed values: default, landscape, portrait.

This allows you to lock orientation and prevent the interface from rotating in response to changes in orientation.

NOTE: The default value means Cordova will strip the orientation preference entry from the platform's manifest/configuration file allowing the platform to fallback to its default behavior. For iOS, to specify both portrait & landscape mode you would use the platform specific value 'all'.

I had the opposite problem then solved it by changing this. I hope this helps!

Upvotes: 0

Related Questions