Is this a correct way of creating a universal iOS app? Xcode 4 - Seems to work?
Here is how I made a universal app from an existing iPhone project by creating ~ipad.xib(s) using duplicate and then adding them back to a backup of the project, and checking universal.
I used xcode 4.02 with a base sdk of 4.3.3 with a deployment target of 3.1.2.
- Back up your whole project somewhere.
- Right click on iPhone target and choose duplicate. Choose duplicate for iPad rather than just duplicate. This makes a new folder called Resources-iPad with a subfolder called classes under that, and under that are copies of all the xib files in the entire project. (The funny thing is that when I look at these files in finder they don't have an .xib extension although they show an extension in the xcode window - why? Finder still says they are xib files anyway though.)
- At this point I had two targets. This seemed wrong so I went to finder and made a backup copy of the new Resources-iPad folder, and then deleted the whole project.
- Copy back the original iPhone project I had backed up up in step 1.
- Added the Resources-iPad folder that was backed up, and edited them so they looked good for iPad.
- I now had one target which seemed good, and I made it a universal device instead of iPhone in the target summary.
- However, I got inconsistent behavior when deploying to the simulator or device - sometimes the wrong xib would be used for no apparent reason.
- This fixed it - in xcode, in the Resources-iPad/classes folder rename all the xibs for ipad from mynibname.xib to mynibname~ipad.xib (tilda in front and all lowercase)
I couldn't find any documentation on whether it is OK to do it this way. It works on these physical devices so far:
iPad 2 with 4.3, iPod touch v1 with 3.1.2, iPod touch v4 (retina) with 4.1
Is this a correct way of creating a universal app? It seems easy enough now that I have this worked out, but took forever to find this info. Oh also I do not have a mainwindow.xib but other nibs that get loaded elsewhere as tableview section hea开发者_Python百科ders and detail views in a tabbar app - so I left the main interface sections blank.
Oh - I don't have an iPad 1 and cant test on that device, but it doesn't seem to work right in the iPad 3.2 Simulator, but all other devices and simulators appear to work OK.
What I have seen a lot of people do is use 2 separate classes for each device. Why? Couldn't tell you!
What I do is use 1 class for both iPad and iPhone, only I use a macro to determine what the current device is:
For Example
#define IDIOM UI_USER_INTERFACE_IDIOM()
#define IPAD UIUserInterfaceIdiomPad
if (IDIOM == IPAD)
{
/* do something specific for iPad. */
} else {
/* do something specific for iPhone, like set up frames. */
}
Of course, you will need to create iPad versions of your Interfaces, but that is the easy part.
As far as identifying it as a Universal app, there is an option in your Project settings, as well as Target Device Family in build settings that you will make sure is set to iPhone/iPad.
That is pretty much all I do to make universal apps, and is quite less time consuming as writing specific classes for each device!
精彩评论