iPad – iPhone code compability in Xcode project

Question: Apple has started selling the iPad and published their iPhone 3.2 SDK. I think it is the right time to start developing iPad applications. First I would like to transfer my existing iPhone apps to the iPad platform. I am having a MacOSX and Xcode on my MacBook. Do you have any advise? Answer: The good news is that iPad runs all iPhone applications without modifications. The iPad will run your existing iPhone apps using the same screen size that is available on the iPhone and iPod touch (ie. 480 x 320 pixels). As you may suspect your applications will utilize less than half of the screen. Applications running in this mode cannot offer full screen for users.
iPhone application on iPad
iPhone application on iPad
Most developers assumed that the iPhone/iPod Touch were always going to be targeting resolutions 480×320 pixels in portrait or landscape orientation. iPhone 4 introduced new screen sizes (960 x 640 pixels) as well. Most programmers must now create a few extra variables and settings to determine the target platform and resolution. This is not a monumental task. See:
    CGSize s = [[UIScreen mainScreen] bounds].size;
    width = s.width;
    height = s.height;
Platform detection is also easy:
// Do not worry the iPhone simulator 3.2+ will get you the iPad simulator,
// or compile for iPhone Device 3.2 or 4.0 and put the app on a phone to test it.
// iPhone 4 has different screen size so do not forget to check the iPhone hardware too


NSString *str;

// Note that UI_USER_INTERFACE_IDIOM() and UIUserInterfaceIdiomPad are NOT defined in the SDKs prior to 3.2.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    // The device is an iPad
    // For example load appropriate iPad nib file
    str = [NSString stringWithString:@"We are running an iPad application"];
} else {
    // The device is an iPhone or iPod touch, but check for screen sizes!
    // For example load your iPhone nib file
    str = [NSString stringWithString: @"We are running an iPhone/iPod Touch application"];

// Let's see what we have found
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Platform check"
[alert show];
[alert release];


// Another bullet proof solution:
- (BOOL) isiPad {
if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)])
    return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
return NO;
iPad project alternatives: 1. Create a universal application that is optimized for all platforms (iPad, iPhone and iPod Touch), or 2. Use a single Xcode project to create two separate applications (iPad and iPhone/iPod Touch), or 3. Use separate Xcode projects to create applications for each platform. We follow Apple’s recommendation. In our projects we create a Universal application, one that targets both the iPhone and the iPad, with separate XIB files representing the UI for each device. Here is an example how you can do that:
// Separate XIB files represent the UI for each device

NSArray *nibViews = nil;
// Read MyOwnView.xib or MyOwnView-iPad.xib
NSString *nameNib = [self isiPad] ? @"MyOwnView-iPad" : @"MyOwnView";

nibViews = [[NSBundle mainBundle] loadNibNamed: nameNib owner:self options:nil];

self.myActualView = nil;
if( nibViews!=nil && [nibViews count] > 0 ){
    self.myActualView = (UIView *)[nibViews objectAtIndex: 0];
    // You have read the view from the proper XIB
Bits and pieces: 1. Application icon on iPad must be 72 x 72 pixels in size. Details on launch images and additional icons of iPhone 3, iPhone 4 and iPad are here. 2. In addition to the Default.png file displayed when your application launches on iPhone devices, you must add new launch images for iPad devices. Visit Apple’s web site for details. 3. Your universal iPhone/iPad app needs more flexibility in terms of enabling and disabling touch based input. With large hands users may find themselves constantly switching pages just by inadvertently touching edges of the screen while holding the device. 4. Please note that Xcode SDK 4 and 3.2.2 includes new project templates for iPad apps and has a menu command (find: Project -> Upgrade Current Target for iPad…) that helps you get the project settings setup correctly. 5. If you need to configure your iPad application differently from your iPhone, you can specify device-specific values for Info.plist keys.
info.plist settings for iPhone/iPad app
Sample info.plist settings for universal iPhone/iPad app
6. We do not advise you separating your project code to handle different platforms. Universial applications can be managed easily. Your application can run on different platforms, ie. on iPod 3, iPhone 3G, iPhone 3GS, iPhone4, iPad… You need proper UI design but the business logic and data tier are surely the same. If you have to manage different projects but have some common tasks to do, as always have, than put these into a static library and link it to the actual project. Read about static library here. Summary: 1. iPad runs all iPhone applications without modifications. iPad is not a phone, but close. Expect WiFi (and 3G, 4G…) network connection. 2. iPad screen resolution is 1024 by 768 pixel. Create a new iPad app icon and add some new launch images to Default.png. Read more info here. 3. Members of the iPhone Developer Program can begin developing iPad applications with iPhone SDK 3.2+. See Apple’s web site. 4. How to update your project in Xcode? – Open your Xcode project – Right click on your target. Select “Upgrade current target to iPad…” – Depending on your preference for multiple target, choose universal or separate targets. Xcode updates your project by modifying several build settings to support both iPhone and iPad. Check out your target -> Get Info -> Targeted Device Family settings. The value must be iPhone/iPad. You should be able to change your target platform in your Project Settings. In iPhone SDK 3.2 switch back to 3.1.3 to test iPhone in the simulator. Find the Hardware menu in the iPhone Simulator to swap iPhone and iPad device. In iPhone SDK 4 you can change the Base SDK to iPhone 4 to test your code in the Mac’s iPhone simulator. In this case you don’t have to switch back to 3.1. Do not skip testing your code on different devices. Advice: run and debug your Universal iPad/iPhone app in the iPad mode simulator first. In universial apps the iPad UI demands more attention. You can debug your app on your iPhone simulator and iPhone/iPod device later. In this case you do not have to switch the simulator from iPad to iPhone and back and you do not be lost. 5. Test and upload your app to the AppStore the same way you did with your previous iPhone projects. We know that App Store is a moving target. Here you can read about the latest challenges. 6. Apple – Adobe war deepens. Adobe will no longer pursue its plans to bring Adobe Flash to iPhone and the iPad. Do not wait for them. Work around the Flash Player problem. 7. Apple’s iPad programming guide is here. Article with detailed step-by-step guide: Port your iPhone apps. Update: Apple has made our life easier and the latest iPhone SDKs for iOS 4.1, 4.2, … offer better tool in developing and debugging universal iPhone apps. Finally it is very simple to set deployment target, and switch between iPhone and iPad simulator, and handle different image sizes for standard, Retina and iPad displays.