0

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
uplearned.com
  • 3,393
  • 5
  • 44
  • 59
  • 1
    Detecting the iPhone Model by screen size is always a bad idea. In fact detecting an iPhone Model is in generally not needed (I don't know any use case for this?). Maybe [UIDeviceHardware](https://gist.github.com/Jaybles/1323251) could help you. – Fabio Poloni Oct 23 '14 at 06:07
  • @FabioPoloni Some companies use these information to do statistic and analyze. – KudoCC Oct 23 '14 at 06:13
  • @KudoCC In that case: The idea of detecting an iPhone by its size is even worse. – Fabio Poloni Oct 23 '14 at 06:14
  • 1
    @FabioPoloni Agreed. – KudoCC Oct 23 '14 at 06:15
  • [This](http://stackoverflow.com/questions/19584208/identify-new-iphone-model-on-xcode-5-5c-5s) will help. – KudoCC Oct 23 '14 at 06:19
  • I've tried detecting the hardware name but this is no help in the simulator. What if you are using the screen size to alter objects placement being displayed on all these devices? – uplearned.com Oct 23 '14 at 12:05
  • 1
    Checking its resolution you can find out which device simulator it is. Try this solution available here : http://stackoverflow.com/questions/25892207/how-to-specify-size-for-iphone-6-customised-edge-to-edge-image?lq=1 – Mrunal Dec 20 '14 at 19:25

2 Answers2

3

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)

Community
  • 1
  • 1
  • Hi thanks but this does not work with the simulator. – uplearned.com Dec 20 '14 at 03:48
  • 2
    It is because the simulator has a different internal name (I updated the answer for the simulator internal name). – Santiago Fabregat Dec 20 '14 at 19:10
  • Hi Santiago though if your working with the simulator it's good to be able to differentiate between the simulators. This stack overflow answer worked the best for me : http://stackoverflow.com/questions/25892207/how-to-specify-size-for-iphone-6-customised-edge-to-edge-image?lq=1 – uplearned.com Dec 20 '14 at 22:59
2

Looking at this guide to iphone resolutions I believe you are running your simulator in zoom mode. So try to disable it:

  1. Launch the iOS Settings app.
  2. Scroll down and select Display & Brightness.
  3. Select the View option under the Display Zoom section.
  4. Preview and select your preferred setting.
Esse
  • 3,278
  • 2
  • 21
  • 25