TECHNIQUE 2 — CREATING UNIVERSAL APPLICATIONS

The previous technique shows how you can modify the Targeted Device Family setting to create a single application that runs on both the iPhone and the iPad, called a Universal application. The challenge is adapting the UI of the application for each platform — you have to programmatically detect the type of device the application is running on and then modify the layout of the UI dynamically.

Apple recommends that you create a Universal application, one that targets both the iPhone and the iPad, with separate XIB files representing the UI for each platform. The following Try It Out demonstrates how you can create a Universal application.

TRY IT OUT: Creating a Universal Application

image

  1. Using Xcode, create a Single View Application project and name it MyUniversalApp. Ensure that you select Universal for the Device Family (see Figure 5-10). You will also use the project name as the Class Prefix. Ensure that the Use Automatic Reference Counting option is unchecked.

    image

    FIGURE 5-10

  2. Observe that you now have two XIB files (see Figure 5-11) in your project.

    image

    FIGURE 5-11

  3. Select the MyUniversalAppViewController_iPhone.xib file to edit it in Interface ...

Get Beginning iOS 5 Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.