Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

iPad Programming: Maintaining Two Code Bases

The third method of developing your application for multiple devices is to maintain separate targets for your app.


advertisement
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 test

Press 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.


   
Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap