Converting App from iPhone to Universal
With the iPad selling like hot cakes it seems like a good idea to get on the bandwagon and make some apps for the iPad. The LogYourRun app is not particularly well suited for running on the iPad – I doubt that people will be strapping their iPads to their arms and run around the park. However, the heart rate app seems like something that people would enjoy using even on iPads. Since I did not want to have to maintain two separate apps I decided to make the app universal. This was actually quite an easy process and took only about 10-12 hours (could have been faster if I had known what I was doing – which is why I wanted to share what I learned).
First step is to make sure you copy your application folder so you will be able to go back to the original application if you mess up. Then with your newly copied application upgrade your target to work on the iPad in addition to the iPhone. Click on your target and go into the menu – under Project you will find an entry that says “upgrade current target for iPad”. Select the “One Universal application” option. This will generate a new group which contains your new iPad version of the MainWindow.xib file – MainWindow-iPad.xib. You can use this new nib to load all your iPad specific views.
At this point I went through all my existing nibs and created iPad versions (can be done in the Interface Builder) and saved them as XxxViewController-iPad.xib in the Resources-iPad folder. For iPad nibs you have to make sure that you have versions of the nib that look decent and are usable in both landscape and horizontal orientations. This can be tricky if you have a lot of UI elements but is very important since iPad apps have to support all orientations. Make sure you anchor your UI elements to the right edges and that they scale to look nice.
The heart rate app uses a tab bar. It took me the longest time to figure out how to get this to rotate. The reason for this was that I had not read Apple’s documentation. Turns out that all the view controllers that the tab bar links to have to return YES for all shouldAutorotateToInterfaceOrientation: orientations. This makes sense conceptually. In addition you need to set your view controllers to automatically resize when rotation occurs. Once these are set you will be able to see what the rotation looks like in the iPad simulator (hopefully great).
Loading the iPad specific nibs using the view controller is a great way to get these to show up on the iPad only – but there are some cases where you will need to load a view controller programatically (in my case when the user clicks on the help button it brings up the help VC). To make sure that you load the right nib you can check if the app is running on the iPad. The following code is what I used:
- (BOOL) isIPad {
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)])
return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
#endif
return NO;
}
This code will check if the iDevice responds to the userInterfaceIdiom selector and if it does it checks if the device is an iPad. If it is I load the iPad version of the helpVC if not then I load the iPhone version of the helpVC. Make sure you also put the respondToRotation in these VCs since they will need to respond predictably also.
Finally you will need to create a default image that can be presented on the iPhone. In your info.plist you can set the “Launch image (iPad)” to the base name of the iPad graphic (e.g. Default-iPad.png). You can then create two images named Default-iPad-Landscape and Default-iPad-Portrait and add them to your project. The iPad will pick whichever of the default images that fits with the rotation of the device.
When uploading your app – build the app in OS3.2. The app will run on both iPhone and iPad from one binary. You will also have to upload screenshots for the iPad version for display in the iPad app store and create two new icons (50×50 and 72×72). Once you have all that together your app is ready for submission and you can start praying that it will be a speedy path to acceptance.