If you are using Titanium Appcelerator to developer applications for mobile devices you may want to restrict which Orientations the app is allowed to use on your devices. This is a fairly simple process and requires you adding some code into your app’s tiapp.xml file.

For IOS

The example below allows portrait only on the iphone and all orientations on the iPad:

<iphone>
<orientations device="iphone">
<orientation>Ti.UI.PORTRAIT</orientation>
</orientations>
<orientations device="ipad">
<orientation>Ti.UI.PORTRAIT</orientation>
<orientation>Ti.UI.UPSIDE_PORTRAIT</orientation>
<orientation>Ti.UI.LANDSCAPE_LEFT</orientation>
<orientation>Ti.UI.LANDSCAPE_RIGHT</orientation>
</orientations>
</iphone>



For Android

Locking orientation on Android can also be done in your app’s tiapp.xml file. It’s more complex though. The primary configuration file for Android apps is the AndroidManifest.xml file. At build time, entries in your project’s tiapp.xml file are used to create the AndroidManifest that’s packaged with your app. To force orientation support, you’ll need to copy some entries from generated AndroidManifest file back into tiapp.xml, modify them, then build your app again.

  • In Studio, open the tiapp.xml file and display its XML contents.
  • Adjust the <android> node:
  • From the line that reads <android xmlns:android=”https://schemas.android.com/apk/res/android”/>, delete the “/” at the end (to change it from an empty tag to an opening tag).
  • Add a new closing </android> tag
  • Between those tags, add new <manifest></manifest> tags.
  • Open the ‘yourProject/build/android/AndroidManifest.xml’.
  • Copy all <activity> lines from that file
  • Then paste between the <manifest></manifest> tags in the tiapp.xml file. Each time your app is built from this point on, Titanium will copy the activity tags to the AndroidManifest file. You’re can now specify the UI orientation.

Each “heavyweight” window has a corresponding activity. And for each of those, you’ll find an entry that reads something like android:configChanges=”keyboardHidden|orientation”. Delete the “|orientation” from each of them.

<android xmlns:android="https://schemas.android.com/apk/res/android">
<manifest>
<activity
android:name="org.appcelerator.titanium.TiActivity"
android:configChanges="keyboardHidden"
android:screenOrientation="portrait"
/>
<activity android:name="ti.modules.titanium.ui.TiTabActivity"
android:configChanges="keyboardHidden"
/>
</manifest>
</android>