3

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

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

because I can't see how it would differentiate between phone and tablet. Currently I've got this in 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>
...
  1. Why doesn't this update my app's foo-Info.plist? I have tried cordova build ios and I have tried cordova prepare commands, neither update the plist file.
  2. When should these changes take effect? When I add the ios platform? when I do cordova build ios?
  3. I also need this to work for Android phone and tablets if you know how.
ABCD.ca
  • 2,365
  • 3
  • 32
  • 24
  • Possible duplicate of [Can i set deferent orientations for IPad and IPhone (Universal) app in cordova?](https://stackoverflow.com/questions/30497799/can-i-set-deferent-orientations-for-ipad-and-iphone-universal-app-in-cordova) – Sébastien BATEZAT Sep 12 '17 at 10:08

1 Answers1

-1

You don't have to hardcode your app name here:

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

To get it working create hooks/after_prepare/011_update_platform_config.js file, take content from here.

Install some npms:

npm install lodash elementtree plist

ionic run, ionic build and ionic prepare commands should update your project files.

For more information check out this topic

P.S.: Your should have a strong reason to use upside-down orientation on an iPhone otherwise it's a pain for users (hello to iBooks).

hryamzik
  • 849
  • 1
  • 9
  • 16