Search code examples
objective-ciphonexcode6screen-sizeuiscreen

How to tell the difference between iPhone 5s/5 and 6 in the Xcode simulator


I've been trying to figure this out for the past few days but keep on getting the same screen size for iPhone 5,5s and 6.--> Height -1136 Width 640. How do I tell the difference between these two devices? Is it the simulator? Do I have to be running on a real device to get the current dimensions? What am I doing wrong? I'm running Xcode 6 on Yosemite and testing with the simulator.

    float heightOfScreen = [[UIScreen mainScreen ] nativeBounds].size.height;
    float widthOfScreen = [[UIScreen mainScreen ] nativeBounds].size.width;
    CGSize size = CGSizeMake(widthOfScreen , heightOfScreen);
    NSLog(@"Size: %@", NSStringFromCGSize(size));


    // Iphone 6 plus H-1704 W-960
    // Iphone 6      H-1136 W-640  <--- (why are they the same)
    // Iphone 5s     H-1136 W-640  <---
    // Iphone 4s     H-960  W-640

Solution

  • Every iPhone has its different internal name:

    - (void)viewDidLoad {
        [super viewDidLoad];  
    
        size_t size;
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
        char *machine = malloc(size);
        sysctlbyname("hw.machine", machine, &size, NULL, 0);
        NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
        NSLog(@"iPhone Device%@",[self platformType:platform]);
    
        free(machine);
    }
    
    
    - (NSString *) platformType:(NSString *)platform
    {
        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,2"])    return @"iPhone 6";
        if ([platform isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
        if ([platform isEqualToString:@"i386"])         return @"Simulator";
        if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
    
        return platform;
    }
    

    And by the way iPhone 4, 5 and 6 all have different screen sizes:

    iPhone 4, 4S:        (640, 960)
    iPhone 5, 5C, 5S:    (640, 1136)
    iPhone 6:            (750, 1334)
    iPhone 6 Plus:       (1080, 1920)
    

    You can refer to this question: Identify new iPhone model on xcode (5, 5c, 5s)