Wasim Safdar
Wasim Safdar

Reputation: 33

Different storyboard for iPhone 6

I am configuring my app to use different storyboards for different iPhones.

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

 if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
if (iOSDeviceScreenSize.height == 480)
{
    // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
    UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_4S" 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];
}
//Not working for iPhone 6 resolution.
if(iOSDeviceScreenSize.height == 667 )
{
UIStoryboard *iphone6Storyboard=[UIStoryboard storyboardWithName:@"Storyboard_Iphone6" bundle:nil];    
UIViewController *initialViewController= [iphone6Storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController  = initialViewController;  
[self.window makeKeyAndVisible];
}
}
return YES;
}

This code is working fine for iPhone4 simulator but for iPhone 6 simulator, it is not working. Everything seems alright but I cannot figure out the problem. It is not detecting the screen resolution for iPhone 6. Please anybody help me.

Upvotes: 0

Views: 193

Answers (2)

SARATH SASI
SARATH SASI

Reputation: 1415

- (NSString *)platformString
{
    NSString *platform = [self platform];

    if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
    if ([platform isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
    if ([platform isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
    if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,3"])    return @"Verizon iPhone 4";
    if ([platform isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([platform isEqualToString:@"iPhone5,1"])    return @"iPhone 5 (GSM)";
    if ([platform isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone5,3"])    return @"iPhone 5c (GSM)";
    if ([platform isEqualToString:@"iPhone5,4"])    return @"iPhone 5c (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone6,1"])    return @"iPhone 5s (GSM)";
    if ([platform isEqualToString:@"iPhone6,2"])    return @"iPhone 5s (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([platform isEqualToString:@"iPhone7,2"])    return @"iPhone 6";

    if ([platform isEqualToString:@"x86_64"])       return @"Simulator";

    return platform;
}

try this one. this code will help you to identify which simulator or device currently running. for complete reference you can use this git hub link

https://gist.github.com/Jaybles/1323251

Upvotes: 0

Nikola Lajic
Nikola Lajic

Reputation: 4075

Your app is probably running in a scaled up mode because you have not added support for the larger phones yet. If that is case the screen height for an iPhone 6 would be reported as 568 points, not 667.

Here is a an SO answer explaining how to properly add support for the larger phones: https://stackoverflow.com/a/25755436/1025574

Upvotes: 2

Related Questions