views:

668

answers:

2

I have an iPad app that I would like to make Universal, however this seems alarmingly difficult. I've changed things around so that I support both builds, but when building, I get lots of errors about using UIPopOvers. Here're my questions:

  • Why does UI_USER_INTERFACE_IDIOM() not compile or register on 3.1.3?
  • Can I conditionally have variables in a class definition based on UI_USER_INTERFACE_IDIOM()?
  • If not, should I make two different view controllers?

Thanks!

+3  A: 

Why does UI_USER_INTERFACE_IDIOM() not compile or register on 3.1.3?

The UI_USER_INTERFACE_IDIOM macro is only available starting with 3.2. Same restrictions for the userInterfaceIdiom property of UIDevice. This means that you can only get universal application starting with SDK 3.2.

Can I conditionally have variables in a class definition based on UI_USER_INTERFACE_IDIOM()?

No. The UI_USER_INTERFACE_IDIOM macro is only a runtime shortcut to get the current UI idiom of the device.

If not, should I make two different view controllers?

If you have very different UI between the two devices, it is wiser to use two different view controllers, and to create the right one at runtime (in the application controller for example) by using the UI_USER_INTERFACE_IDIOM macro.

Laurent Etiemble
So, if I wanted a Universal app, do I build for 3.2? I don't understand, no iPhones or iPod touches can run 3.2, so I can't use `UI_USER_INTERFACE_IDIOM()` at all. Should I be building for 3.2 and just use both arm build settings? How do I test on a device not running 3.2, like an iPhone?I can't seem to get things to compile on 3.1.3 either because `UIPopoverController` isn't recognized under that version.
Peter Hajas
Yes, universal app are only available starting with 3.2. For the moment, no stock iPhone runs the SDK 3.2, but the iPad do.So developing an universal app implies setting the base SDK to 3.2 and setting the target SDK to 3.1+. Then you have to perform runtime checks in order to check is the 3.2 classes or functions are available.I recommend the reading of the iPad Programming Guide (http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/StartingYourProject/StartingYourProject.html) that describes how to make universal apps.
Laurent Etiemble
+2  A: 

I had pretty good luck with just selecting the target then going to Project->Upgrade current target for iPad.

My app is pretty simple, consisting mostly of table views and webviews, but it's worth making a backup and trying...

And yes, you have to submit it as a 3.2 app that can target 3.1.*

There are also a lot of other stuff that you have to do: Make sure that it can be viewed at any orientation (got rejected the first time for this). Make sure that you have all the new images created. you have to have 3 or 4 icons, instead of just one like an iPhone app needed. (iPad icon, iPhone icon, small icon for spotlight, etc). And of course iPad sized screenshots for the store.

A really nice way that I use to test if it's an iPad or iPhone is to check if the device can use a split view controller, since for the forseeable future no device with a screen as small as an iPhone will be able to use the split view controller. I just created a function to do this for me:

+(BOOL)isIpad{ return NSClassFromString(@"UISplitViewController") != nil; }

Then anywhere in my app that I want to display something different depending on device, I just do a check for it:

int width = 150;
if([NabAppDelegate isIpad]){
   width = 350;
} else {
   width = 150;
}
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5,10,width,25)];

This is a lot better than checking against OS version like I've seen some suggest.

AndyD273