How do I customize the iOS orientation in the config.xml cordova for a universal app?

I have a universal app and only want portrait orientation for iPhone and landscape orientation for iPad. I don't believe I can just do

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

because i dont see how it will differentiate between phone and tablet. Currently I got this at the root:

...
<platform name="ios">
    <config-file target="foo-Info.plist" platform="ios" parent="UISupportedInterfaceOrientations">
        <array>
            <string>UIInterfaceOrientationPortrait</string>
            <string>UIInterfaceOrientationPortraitUpsideDown</string>
        </array>
    </config-file>

    <config-file target="foo-Info.plist" platform="ios" parent="UISupportedInterfaceOrientations~ipad">
        <array>
            <string>UIInterfaceOrientationLandscapeLeft</string>
            <string>UIInterfaceOrientationLandscapeRight</string>
        </array>
    </config-file>
...
</platform>
...

      

  • Why is this updating my foo-Info.plist application? I tried cordova build ios

    and I tried commands cordova prepare

    without updating the plist file.
  • When do these changes take effect? When do I add the ios platform? when do i do cordova build ios

    ?
  • I also need this to work on android phone and tablets if you know how.
+3


source to share


1 answer


You don't need to hardcode the name of your app here:

<config-file platform="ios" target="*-Info.plist" parent="UISupportedInterfaceOrientations">

      

To make it work create a file hooks/after_prepare/011_update_platform_config.js

, grab the content here .

Install some npms:



npm install lodash elementtree plist

      

Commands

ionic run

, ionic build

And the ionic prepare

need to update the files in your project.

See this section for more information .

PS: You must have a good reason to use inverted orientation on iPhone, otherwise it is a pain for users (hello iBooks).

-1


source







All Articles