Universal app question

Discussion in 'iOS Programming' started by MACloop, Aug 9, 2010.

  1. macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #1
    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
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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
     
  3. thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #3
    Thanks for the answer! OK, I will look into the documentation again. I suppose I missunderstood that part. Thanks!
    MACloop
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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...
     
  5. thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #5
    Yes I found it - thanks for the hint! It works!
    MACloop
     
  6. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    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.
     
  7. thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #7
    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
     
  8. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    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.
     

Share This Page