How to edit default orientation in Cordova build?

I have a cordova app using media queries to display different layouts in portrait or landscape. However, it is locked in portrait view and will not respond to a change in orientation. I found this post that mentions making the following change to the config.xml file:

<platform name="ios">
    <preference name="Orientation" value="all" />
</platform>

I added this preference to myProject/.meteor/local/cordova-build/config.xml. However, when I re-run meteor run ios-device --mobile-server=myDomain, the change gets overwritten.

Where should I add this preference so that it survives the build?

Meteor uses its own configuration file called mobile-config.js. This will auto-create the settings for config.xml and hence override values that you add manually there.

Add this line to mobile-config.js:

App.setPreference('Orientation', 'all', 'ios');

and you’re good.

More on the file can be found here:

In the rare cases where you have to add values to config.xml (or to Xcode settings) that are not available via mobile-config.js, you would have to implement a Cordova plugin that includes a build hook:

https://cordova.apache.org/docs/en/latest/guide/appdev/hooks/

I use this approach to auto-set my dev team in Xcode and disable Bitcode, for instance. But for most use-cases, this complexity is not needed.

Thank you, all set now!

1 Like