0

I need to launch a specific storyboard if the device is an iPhone 5 and another one if the device is an iPhone 4S or older. I know that I need to add some code do the didFinishLaunchingWithOptions method but I don't know which precisely!

Anyone can give me the correct code?

Cœur
  • 37,241
  • 25
  • 195
  • 267

3 Answers3

1

There is a great solution to this problem in this question:

xcode 4.5 how to pick storyboards at launch

Essentially, you can check the screen height in didFinishLaunchingWithOptions and load the appropriate scoreboard.

Community
  • 1
  • 1
Larry Hipp
  • 6,205
  • 3
  • 26
  • 31
0

You have to define two different storyboards. One for the iPhone 4 dimensions and one for the iPhone 5 dimensions.

Then add the following code to your application delegate application didFinishLaunchingWithOptions method...

// Override point for customization after application launch.
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

if (iOSDeviceScreenSize.height == 480)
{
    // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
    UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"iPhone4" bundle:nil];

    // Instantiate the initial view controller object from the storyboard
    UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController];

    // Instantiate a UIWindow object and initialize it with the screen size of the iOS device
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Set the initial view controller to be the root view controller of the window object
    self.window.rootViewController  = initialViewController;

    // Set the window object to be the key window and show it
    [self.window makeKeyAndVisible];
}

if (iOSDeviceScreenSize.height == 568)
{   // iPhone 5 and iPod Touch 5th generation: 4 inch screen
    // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
    UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"iPhone5" bundle:nil];

    UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController  = initialViewController;
    [self.window makeKeyAndVisible];
}
return YES;

Or you could always try your luck with autolayout. Either way works.

Jude Michael Murphy
  • 1,198
  • 2
  • 12
  • 23
0

You can check for iPhone 4/iPhone 5 and instantiated a storyboard according to it

Following code even tells you iPhone or iPad.

Can save iPhone or iPad bool globally through-out the App.

Note: by default iphone4 storyboard will be instantiated.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{


iPhone5 = NO;
iPad = NO;

// Override point for customization after application launch.
UIStoryboard *storyBoard;

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    if ([UIScreen mainScreen].scale == 2.0f)
    {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        CGFloat scale = [UIScreen mainScreen].scale;
        result = CGSizeMake(result.width * scale, result.height * scale);

        if(result.height == 960)
        {
            iPhone5 = NO;
           // NSLog(@"iPhone 4, 4s Retina Resolution");
        }
        if(result.height == 1136)
        {
            iPhone5 = YES;
          //  NSLog(@"iPhone 5 Resolution");
            storyBoard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
            UIViewController *tabBarController = [storyBoard instantiateInitialViewController];
            self.window.rootViewController = tabBarController ;
        }
    }
    else
    {
      //  NSLog(@"iPhone Standard Resolution");
        iPad = YES;
    }
}
else
{
    iPad = YES;
}

return YES;

}

user2495996
  • 51
  • 1
  • 4