Whats the best way to create an iPhone and an iPad application simultaneously? - iphone

I have an iPhone app that I would like to port over to the iPad, but I would like to have as little duplication as possible.
How do people usually go about doing this?
In xcode can you have different targets for iPhone and iPad and perhaps do some pre-processor checks? Or is it best to simply have two separate projects altogether?
Note, Im NOT talking about running the iPhone app on the iPad, I mean creating a native 3.2 app...
EDIT
So it looks like creating a universal application is the way to go:
http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/StartingYourProject/StartingYourProject.html#//apple_ref/doc/uid/TP40009370-CH9-SW8
But what I still dont understand is how to select different NIB files based on your current deployment???
Thanks a lot

For minimal duplication, you can use one project, with 2 sets of .nib files, but one set of source code files which include run-time checks for the UIUserInterfaceIdiom differences.
If you want two (or more) apps instead of a Universal app, just create two targets containing only the appropriate .nib files, and #ifdef the run-time check results using a Preprocessor Macro define in each target's Build Settings to force iPhone or iPad idiom only.

The latest (3.2.3) Xcode auto-generates a Universal project which is a great starting point to see how to target iPad and iPhone in one Xcode project.
File > New Project > Window-based Application > Product : Universal

Related

Moving from universal iOS app to separate iPhone/iPad apps

I started developing a universal app because I was told to do that way as a requirement, but now I'm being asked about the possibility of switching to separate iPhone and iPad versions and I need to give an idea of the effort that making this change will have.
I've been looking for posts dealing with this issue but what I found mostly dealt with moving from separate to universal, not in reverse, so I need somebody who had to do the same to help me to make clear some questions I have:
1) Having a project target set to universal, if I simply set it to iPhone or iPad, does the build ignore all the resources the app won't need (~iPad resources if set to iPhone, and viceversa), or it will include them in the build anyway? Is it needed to remove the unnecessary resources from the target's build phases section?
2) So, should I create two more targets in addition to the universal one, or is it enough to change the device in my current target to the one I need, iPhone or iPad, and just build it?
Thanks in advance

Is there a global way to merge an iPhone and an iPad app into a universal app?

I wrote an iPhone app. Then, I changed the interface a fair bit, added higher res images, and made an iPad version of it. In a perfect world, I would like for anyone who buys the iPad version to get the iPhone version for free (though not conversely). Since Apple doesn't seem to have a way to do that (right??), my next favorite solution is to make the iPad version include the iPhone version somehow.
I know that I could just convert the iPad version to "universal", but since the face of the app is so different, that seems like a real pain. I have many view controllers and they are almost completely different between the two versions. Some of the methods are the same, but only about 30%. Is there an easy solution along the lines of this:
Check if device is iPhone or iPad
If iPhone, then use one group of files
If iPad, then use a different group of files
Thanks in advance!
Try creating a new project in Xcode and choose to make it a universal app. In the default way Xcode lays it out, there is a distinct divide between the iPad and iPhone versions. You can make the two versions of the app as similar or different as you want.
In addition, you can check which device you are running on at runtime by using UI_USER_INTERFACE_IDIOM(). Currently the two values for this are UIUserInterfaceIdiomPad and UIUserInterfaceIdiomPhone.
The "easy solution" you describe is basically how iOS loads Universal apps.
There's no other real way around it. You'll have to merge your two projects into one again to do what you want.
The first problem will be that some (many?) names of classes will be common between both projects. You can save yourself some pain by using the "Refactor..." functionality in Xcode to change the names of the classes in one project (say, your iPhone app, since it's older) before you merge them together. The second problem will be your Info.plist; you'll need to ensure that the correct "Main nib file base name", the correct supported interface orientations, icon files, and so on are set to correct values for both iPad and iPhone respectively.

Make iPad-xib from iPhone-xib

I am searching the web for a while now and didnĀ“t find the answer...
is it possible in Xcode4 to convert an iPhone.xib to an iPad.xib when upgrading to a universal-app?!?
in Xcode 3 there was a possibility to create an ipad.xib from a selected iphone.xib. is this feature still available under Xcode4?
AFAIK universal app in Xcode uses two different xibs, so when "upgrading" to universal app - you actually have to write code to know which xibs to load as well as create separate xibs for iphone and ipad.

How to get multiple targets into one binary for app store submission?

I have split my iPhone app into two targets one for the ipad and one for the iphone. When I upload to the appstore I can only have one binary. But I have two targets?
I think I am missing a step. Thanks in advance for any help.
A "target" encompasses all of the instructions that Xcode uses to build your app.
You can have two targets inside of one binary, although this is not always done. This is how Universal Binaries are made. The two apps are bundled together inside of one binary. If you open up a Mac app "bundle" you will notice a few meta files, like icons and such, and there will be the actual compiled binary code. An iOS Universal Binary has both apps inside of it.
(If you watch your compilation carefully, you'll notice that Xcode actually builds your app twice. It does one build for iPhone/iPod and one for iPad.)
Provided that your Xcode project is set up properly, you will get the intended results.
The binary will be fine, the "targets" refer to what runs when it is run on an iPhone vs iPad. If the project is setup correctly for universal it should work fine.

iOS - iphone/ipad versioning

I currently have an iphone app that I want to make an ipad version of. I don't want it to be "universal" though. I want to sell the ipad version for a different price than the iphone version.
My question - what is the best way to go about this in Xcode? Do I just copy the project and then maintain two separate projects, and do the ipad build from the new project? Seems this is the only way to go, but will be a pain to make updates to both. Suggestions? Advice? Thanks.
In almost the same way that you would make an app universal, you can make a separate iPad version. Disclaimer: I haven't actually done this before, I went the universal route. Now what you need to do is first right click on your target and click "Upgrade Current Target for iPad..." Then click "Two device-specific applications" and "OK." Good luck.
I went through something similar with my apps. I had a working iPhone version of an app that I wanted to port to the iPad. I created an iPad-specific project and added the share-able code to this. Fortunately for me, I had a pretty clean separation of the data and UI code and was able to share most of the data code; in the new iPad project, the only thing I had to write new code for was the UI stuff.
I'm totally open to changing the way I handle this separation. In theory, it would seem that you could specify different bundle identifiers and turn on/off settings to enable iPad or iPhone versions. But I had decided that it'd just be simpler to separate out my iPad/iPhone projects.
Hope this helps!
Instead of using two projects, add an iPad app target to your iPhone project. This way, whenever you change shared code, it is updated for both apps.