Using Titanium iOS Specific Configurations

Starting with the release of Titanium Mobile 2.1 iOS specific configurations have been moved under an ios node in the tiapp.xml similar to Android.  This is quickly becoming one of my favorite features.

Using the new iOS Section

The new iOS configuration section allows you to include native plist settings into your tiapp.xml file. At compile time, Titanium will use these settings when generating your project’s Info.plist. This reduces the need to use a custom Info.plist in your project, and makes it much easier to compare your Titanium settings with those in your xcode project.

For example here is a tiapp.xml with a few modifications.

<?xml version="1.0" encoding="UTF-8"?>
<ti:app xmlns:ti="http://ti.appcelerator.org">
    <deployment-targets>
        <target device="mobileweb">false</target>
        <target device="iphone">true</target>
        <target device="ipad">false</target>
        <target device="android">true</target>
        <target device="blackberry">false</target>
    </deployment-targets>
    <sdk-version>2.2.0.v20120710</sdk-version>
    <id>com.appworkbench.modtest</id>
    <name>ModeTest</name>
    <version>1.0</version>
    <publisher>benCoding</publisher>
    <url>http://test.com</url>
    <description>not specified</description>
    <copyright>2012 by benCoding</copyright>
    <icon>appicon.png</icon>
    <analytics>false</analytics>
    <guid>b8962c32-58ec-458f-8c93-bf6b7dbad5d2</guid>
<ios>
<plist>
<dict>
<key>UIPrerenderedIcon</key><true/>
<key>UIStatusBarStyle</key><string>UIStatusBarStyleBlackTranslucent</string>	
<key>UISupportedInterfaceOrientations</key>
<array>
   	<string>UIInterfaceOrientationPortrait</string>
   	<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UIBackgroundModes</key>
<array>
   	<string>location</string>
 	</array>
</dict>	
</plist>
</ios>    
    <android xmlns:android="http://schemas.android.com/apk/res/android"/>
    <modules>
    </modules>
</ti:app>

You can easily see how each of the components map to the generated Info.plist.

plist Sample

Adding Other iOS Configuration Elements

You can also add other iOS configuration elements quickly.  In the example below we show adding an entry for UIApplicationExitsOnSuspend to close the app when placed into the background and requiring the device has a flash by using UIRequiredDeviceCapabilities.

<ios>
	<plist>
		<dict>
			<key>UIPrerenderedIcon</key><true/>
			<key>UIStatusBarStyle</key><string>UIStatusBarStyleBlackTranslucent</string>	
			<key>UIApplicationExitsOnSuspend</key><true/>
			<key>UIRequiredDeviceCapabilities</key>
				<array>
				   <string>camera-flash</string>
				</array>	 	
		</dict>	
	</plist>
</ios>

Titanium generates the correct Info.plist entries as shown below.

Adding More Entries

Adding Custom Fonts

The new iOS section removes the need to use a predefined plist for Custom Font support.  You now can define your fonts directly in your tiapp.xml and Titanium will handle the rest.

For example, we’ve added the below reference to our custom font “blah.otf”.

<ios>
	<plist>
		<dict>
			<key>UIPrerenderedIcon</key><true/>
			<key>UIStatusBarStyle</key><string>UIStatusBarStyleBlackTranslucent</string>	
			<key>UISupportedInterfaceOrientations</key>
				<array>
				   	<string>UIInterfaceOrientationPortrait</string>
				   	<string>UIInterfaceOrientationPortraitUpsideDown</string>
				</array>
			<key>UIAppFonts</key>
				<array>
				   	<string>blah.otf</string>
				</array>	 	
		</dict>	
	</plist>
</ios>

Titanium generates the correct Info.plist entries as shown below.

Custom Fonts Sample

You can read more about using Custom Fonts in your project here https://wiki.appcelerator.org/display/guides/Custom+Fonts

Helpful References

For more information please reference the iOS Specific Section documentation here.

Not all plist values are supported so you will want to pay special attention to those listed here

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s