PDA

View Full Version : Universal app question




MACloop
Aug 9, 2010, 03:28 AM
Hello,
I have read the documentation for universal apps and came to the conclusion that the following has to be done in order to get an app run on both iPad and iPhone/iPod touch:

1. I have configurated my iPhone app using Xcode’s Upgrade Current Target for iPad.
2. In the AppDelegate, I have seperated the code to be used when running on the different devices as follows in the .h file:


@interface AppDelegate : NSObject <UIApplicationDelegate, DataAccessDelegate, CLLocationManagerDelegate> {
UIWindow *window;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
iPadViewController *viewController;
RotatingTabBarController *tabBarController;
#else
UITabBarController *tabBarController;
#endif


and in the .m file

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
IPADstartViewController *myViewController;
myViewController = [[IPADstartViewController alloc] initWithTabBar];
#else
startViewController *myViewController;
myViewController = [[startViewController alloc] initWithTabBar];
#endif

localNavigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];

[localControllersArray addObject:localNavigationController];// to the array of controllers
[localNavigationController release];// release since we are done with this for now
[myViewController release];


My problem is:
It seem to work when chosing the iPad simulator 3.2 but if I chose the iPhone simulator 4.0 I get problems. The iPhone simulator is opened up but it tries to open up a view with a popovercontroller and is off course crashing. So - the question is: is this the proper way to seperate code in the appDelegate?

Thanks in advance!
MACloop



robbieduncan
Aug 9, 2010, 03:50 AM
You are separating your code in iOS version, nothing to do with the hardware. iOS 4.0 (on the iPhone 4) has a version >= 30200 so it's executing your "iPad" path.

You should be using the UI_USER_INTERFACE_IDIOM function that is described and documented in the iPad Programming Guide (http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/StartingYourProject/StartingYourProject.html). I think you need to take a little more care as you read the docs :p

MACloop
Aug 9, 2010, 03:52 AM
You are separating your code in iOS version, nothing to do with the hardware. iOS 4.0 (on the iPhone 4) has a version >= 30200 so it's executing your "iPad" path.

You should be using the UI_USER_INTERFACE_IDIOM function that is described and documented in the iPad Programming Guide (http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/StartingYourProject/StartingYourProject.html). I think you need to take a little more care as you read the docs :p

Thanks for the answer! OK, I will look into the documentation again. I suppose I missunderstood that part. Thanks!
MACloop

robbieduncan
Aug 9, 2010, 03:58 AM
Thanks for the answer! OK, I will look into the documentation again. I suppose I missunderstood that part. Thanks!
MACloop

Scroll down that page I linked to to the section "Using Runtime Checks to Create Conditional Code Paths". It has a code example for exactly what you are trying to do...

MACloop
Aug 9, 2010, 04:55 AM
Scroll down that page I linked to to the section "Using Runtime Checks to Create Conditional Code Paths". It has a code example for exactly what you are trying to do...

Yes I found it - thanks for the hint! It works!
MACloop

PhoneyDeveloper
Aug 9, 2010, 11:35 AM
The whole point of a Universal app is that it's a single binary that can run on multiple hardware and OS platforms. The checks where one code path or another needs to be run need to be runtime checks, not compile time checks.

MACloop
Aug 10, 2010, 08:01 AM
The whole point of a Universal app is that it's a single binary that can run on multiple hardware and OS platforms. The checks where one code path or another needs to be run need to be runtime checks, not compile time checks.

Hello,
yes I noticed that and it makes sence. Now, I have an app running either on the iPhone or the iPad. If I (in the simulator) pic the iPad simulator it is running using the iPad simulator. If I pic the iPhone simulator, it is running in the iPhone simulator. I have different viewControllers for the different devices, but the functionality classes (like parsing, data access etc) do the share. In the appdelegate i do some choices depending on the current device.

Is this the way to think when creating Universal Apps?

MACloop

PhoneyDeveloper
Aug 10, 2010, 08:52 AM
Pretty much.

In one app of mine I have all the view controllers work for both iPad and iPhone. There are only a few places where there is code that is specific to one platform or the other and I have the runtime checks there. If there would be a lot of differences then it makes sense to have different view controllers so code can be organized easier and be more efficient.