YouTip LogoYouTip

Ios Universal Applications

* * * ## Introduction A universal application is an app designed for both iPhone and iPad in a single binary file. This helps with code reuse and enables faster updates. ### Example Steps 1. Create a simple View-based application. 2. On the right side of the file viewer, rename the file `ViewController.xib` to `ViewController_iPhone.xib`, as shown below: ![Image 1: UniversalAppInterfaceRename](#) 3. Select "File -> New -> File...", then choose User Interface, select View, and click Next: ![Image 2: NewIpadXib](#) 4. Choose iPad as the device and click Next: ![Image 3: UniversalAppSelectDeviceType](#) 5. Save this file as `ViewController_iPad.xib`, then select Create. 6. Add a label to the center of the screen in both `ViewController_iPhone.xib` and `ViewController_iPad.xib`. 7. In `ViewController_iPhone.xib`, select the Identity Inspector and set the custom class to `ViewController`: ![Image 4: UniversalAppSetClass](#) 8. Update the `application:didFinishLaunchingWithOptions:` method in `AppDelegate.m`: ```objective-c - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [ initWithFrame:[ bounds]]; // Override point for customization after application launch. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { self.viewController = [ initWithNibName:@"ViewController_iPhone" bundle:nil]; } else { self.viewController = [ initWithNibName:@"ViewController_iPad" bundle:nil]; } self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; } ``` 9. In the project summary, update the Devices setting to "universal," as shown below: ![Image 5: UniversalAppSetDevices](#) ### Output When you run this application, you will see the following output: ![Image 6: UniversalAppiPhone_Output](#) Running the application on the iPad simulator produces the following output: ![Image 7: UniversalAppiPad_Output](#)
← Ios CameraIos Accelerometer β†’