Search code examples
iphonexcodeipadproject

How to start a project with both outputs iPhone & iPad?


Using the Pre Release Xcode 3.2.3 I get this as a Startup Project

alt text
(source: balexandre.com)

What should I chose / do to great a project that can have both iPad and iPhone as a target (not showing the iPhone App on iPad but a real iPad View)?

Thank you.


To avoid problems:

  • iPhone OS 3.1.3 is the latest release on iPhone
  • iPhone OS 3.2 is the latest release on iPad

My question does not infringe any agreements that me and Apple are bound to, as my question is regarding those already public Releases.

I just stated that on my Operating System I'm running the Xcode 3.2.3, that is all.


Solution

  • just found out a simple way:

    alt text http://www.balexandre.com/temp/2010-04-17_1242.png

    alt text http://www.balexandre.com/temp/2010-04-17_1241.png

    Then, if you want to switch to XIB files per device, let's say, the MainView for iPhone is A and the MainView for iPad is B, in your AppDelegate you add this:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
        // The default have the line below, let us comment it
        //MainViewController *aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
    
        // Our main controller
        MainViewController *aController = nil;
    
        // Is this OS 3.2.0+ ?
        #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
    
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
                // It's an iPad, let's set the MainView to our MainView-iPad
            aController = [[MainViewController alloc] 
                                  initWithNibName:@"MainView-iPad" bundle:nil];
        else 
                // This is a 3.2.0+ but not an iPad (for future, when iPhone runs with same OS than iPad)
            aController = [[MainViewController alloc] 
                                  initWithNibName:@"MainView" bundle:nil];
    
        #else
            // It's an iPhone (OS < 3.2.0)
            aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
        #endif
    
        // Let's continue our default code 
        self.mainViewController = aController;
        [aController release];
    
        mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
        [window addSubview:[mainViewController view]];
        [window makeKeyAndVisible];
    
        return YES;
    }