devxlogo

iPad Programming: Maintaining Two Code Bases

iPad Programming: Maintaining Two Code Bases

Now that Apple has started selling the iPad and the NDA lifted on the iPhone 3.2 SDK, it is time for developers to start developing iPad applications. And for a large number of developers, developing iPad applications means porting their existing applications to the iPad platform.

Though the iPad is also running the iPhone OS, there are some subtle differences that developers need to look out for when porting their applications over to the new device. This article, the second of two, examines another way that you can port your existing iPhone apps to the iPad. The first article, “iPad Programming: Port Your iPhone Apps, Part I,” dealt with two methods: supporting both the iPhone and iPad platforms, and creating universal applications.

Method 3: Maintaining Two Code Bases

The third method of developing your application for multiple devices is to maintain separate targets for your application. Using this approach, you will have two executables eventually — one for iPhone/iPod touch, and one for iPad. The following steps will show you how to accomplish this. Using Xcode, create a View-based Application (iPhone) project and name it MyAppiPhone. Expand on the Targets item and select the MyAppiPhone item. Select Project’Upgrade Current Target for iPad …In the dialog, select the “Two device-specific applications” option and click OK (see Figure 1). Figure 1. Selecting the device-specific option.Observe the following items created by Xcode (see Figure 2). Figure 2. Examining the files created by Xcode.Two sets of resources and targets will be created for you — one for iPhone and one for iPad. You need to maintain two separate sets of files for each platform.To test the application on the iPhone Simulator, select iPhone Simulator 3.1.3 (under the Active SDK; see Figure 3) and MyAppiPhone (under Active Target).

Figure 3. Selecting the SDK and target to test.Press Command-R. Your application will run as an iPhone application (see Figure 4). Figure 4. The application running on the iPhone Simulator.To test the application on the iPad Simulator, select iPhone Simulator 3.2 (under the Active SDK; see Figure 5) and MyAppiPhone-iPad (under Active Target).

Figure 5. Selecting the SDK and target to testPress Command-R. Your application will run as an iPad application (see Figure 6). Figure 6. The application running on the iPad Simulator.Like the Universal application approach, you need to maintain two sets of resources. In this example, both the XIB files are connected to the same view controller (MyAppiPhoneViewController). However, it does have two separate targets – one for the iPhone and one for the iPad. Because of this, there will be two separate executables for your application.

Summary

In these two articles, you have seen how to port an existing iPhone application to support both the iPhone and the iPad. In general, the Universal application approach is the recommended one as it allows you to maintain just one code base that can target multiple platforms.
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist