iOS Universal app question

MACloop

macrumors 6502
Original poster
May 18, 2009
393
0
Germany
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:
Code:
@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
Code:
#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

Moderator emeritus
Jul 24, 2002
25,275
556
Harrogate
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. I think you need to take a little more care as you read the docs :p
 

MACloop

macrumors 6502
Original poster
May 18, 2009
393
0
Germany
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. 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

Moderator emeritus
Jul 24, 2002
25,275
556
Harrogate
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...
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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

macrumors 6502
Original poster
May 18, 2009
393
0
Germany
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

macrumors 68040
Sep 2, 2008
3,114
93
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.