Easy Tutorial
❮ Ios Application Debugging Ios Objective C ❯

Universal iOS App


Introduction

A universal app is designed for both iPhone and iPad within a single binary file. This facilitates code reuse and allows for quicker updates.

Example Steps

  1. Create a simple View-based application.

  2. In the file explorer on the right, rename the file ViewController.xib to ViewController_iPhone.xib as shown below.

  3. Select "File -> New -> File...", then choose User Interface, select View, and click Next.

  4. Choose iPad as the device and click Next.

  5. Save the file as ViewController_iPad.xib and then select Create.

  6. Add a label in the center of the screen for both ViewController_iPhone.xib and ViewController_iPad.xib.

  7. In ViewController_iPhone.xib, select the identity inspector and set the custom class to ViewController.

  8. Update the application:DidFinishLaunching:withOptions method in AppDelegate.m.

    - (BOOL)application:(UIApplication *)application
      didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
       self.window = [[UIWindow alloc] initWithFrame:[[UIScreen 
       mainScreen] bounds]];
       // Override point for customization after application launch.
       if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
            self.viewController = [[ViewController alloc] 
            initWithNibName:@"ViewController_iPhone" bundle:nil];
       }
       else{
            self.viewController = [[ViewController alloc] initWithNibName:
            @"ViewController_iPad" bundle:nil];
       }
       self.window.rootViewController = self.viewController;
       [self.window makeKeyAndVisible];
       return YES;
    }
    
  9. Update the device to universal in the project summary as shown below.

Output

Running the application, we will see the following output.

Running the application on the iPad simulator, we will get the following output.

❮ Ios Application Debugging Ios Objective C ❯