Info.plist and other iOS tips for beginners tagged:

Info.plist and other iOS tips for beginners

Posted by in Coding Tricks, iOS

After starting work on Apple’s iOS mobile platform I have learnt several tips that were at first not obvious. These have made my life easier and can easily be found elsewhere on the web but I feel that putting them together will help me in the future and hopefully some other iOS beginners.

Info.plist

The Info.plist is an XML file that is bundled with your application. It is auto generated in Xcode and can be found in the resources group. It is a dictionary with keys and values, these values can be edited or more keys can be added. Editing this file in Xcode provides several benefits. It makes setting boolean values and such much easier and allows collapsing and expanding of XML tags. There is also the “Show Raw Keys/Values” and option (found on the right click menu of the Info.plist file). When this option is turned off each property will have a description as opposed to only their keys.

There are many properties in here that are useful, such as setting the icon and name of application. The following settings are however the ones that I would not have thought to look for in here and have found very useful.

UIApplicationExitsOnSuspend or “Application does not run in background”: This does exactly what the descriptive title says and does not allow your application to run in the background. This is useful when you are creating an application that does not need to save it’s state and should restart every time it is run.

UIStatusBarHidden or “Status bar is initially hidden”: This again does exactly what the descriptive title says and hides the black status bar across the top of the screen when the app is started. This is great for making a splash screen look good at full screen size. If you want to bring the status bar back the following piece of code will help.

if ([[UIApplication sharedApplication] isStatusBarHidden])
{
     [[UIApplication sharedApplication] setStatusBarHidden:NO];
}

UIAppFonts or “Fonts provided by application”: This is an array that tells the application what custom fonts were provided. In order to load a custom font do the following steps.

  1. Add the font file into your projects resources folder, the files can be ‘TTF’ or ‘OTF’
  2. Create the UIAppFonts entry in your Info.plist
  3. Add an item to the UIAppFonts entry with the filename of your font, e.g. “LegacySansStd-Book.otf”
  4. Create a UIFont object with the added font. This is done with the following code: [UIFont fontWithName:<FontName> size:<size>]. Here the <FontName> is not the same as the file name but the actual font name. To find this name open the font, the font name is written on the top of the Font Book window. Here the name is “ITC Legacy Sans Std”, so your call would become [UIFont fontWithName:@"ITC Legacy Sans Std" size:17].
  5. Set your GUI element’s font to the font you created.

Splash Screens

Another great tip was adding a Default.png file to your resources group. This image is the first thing loaded by your application and is then displayed while the rest of your application loads, i.e. your splash screen. If you are creating an iPad application you should rather add Default-Portrait.png and Default-Landscape.png as iPad applications must run in landscape and portrait. Depending on the device’s orientation one of the two will be loaded as the splash screen.

Properties

Creating properties for your classes can be tedious involving 4 steps. Fortunately I was shown a script that automated a lot of this process, I can not even begin to say how much time this has saved me. cocoawithlove.com is the blog I original got it from and contains the script as well as instructions on how to use it.