Detecting iPhone 6 6 screen sizes in point values

0 votes

Given the newly announced iPhone 6 screen sizes:

iPhone 6: 1334h * 750w @2x (in points: 667h * 375w)
iPhone 6+: 1920 * 1080 @3x (in points: 640h * 360w)

I was wondering if there is code that allows me to detect which screen size the user's device is, so that I could adjust and size UIImages and other materials accordingly with the user's device.

So far, I have been using the following:

- (NSString *) platform{
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithUTF8String:machine];
    free(machine);
    return platform;
}

- (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:@"iPod1,1"])      return @"iPod Touch 1G";
    if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
    if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
    if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
    if ([platform isEqualToString:@"iPod5,1"])      return @"iPod Touch 5G";
    if ([platform isEqualToString:@"iPad1,1"])      return @"iPad";
    if ([platform isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
    if ([platform isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
    if ([platform isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
    if ([platform isEqualToString:@"iPad2,4"])      return @"iPad 2 (WiFi)";
    if ([platform isEqualToString:@"iPad2,5"])      return @"iPad Mini (WiFi)";
    if ([platform isEqualToString:@"iPad2,6"])      return @"iPad Mini (GSM)";
    if ([platform isEqualToString:@"iPad2,7"])      return @"iPad Mini (GSM+CDMA)";
    if ([platform isEqualToString:@"iPad3,1"])      return @"iPad 3 (WiFi)";
    if ([platform isEqualToString:@"iPad3,2"])      return @"iPad 3 (GSM+CDMA)";
    if ([platform isEqualToString:@"iPad3,3"])      return @"iPad 3 (GSM)";
    if ([platform isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
    if ([platform isEqualToString:@"iPad3,5"])      return @"iPad 4 (GSM)";
    if ([platform isEqualToString:@"iPad3,6"])      return @"iPad 4 (GSM+CDMA)";
    if ([platform isEqualToString:@"iPad4,1"])      return @"iPad Air (WiFi)";
    if ([platform isEqualToString:@"iPad4,2"])      return @"iPad Air (Cellular)";
    if ([platform isEqualToString:@"iPad4,4"])      return @"iPad mini 2G (WiFi)";
    if ([platform isEqualToString:@"iPad4,5"])      return @"iPad mini 2G (Cellular)";
    if ([platform isEqualToString:@"i386"])         return @"Simulator";
    if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
    return platform;
}

As such, should I assume iPhone7,1 and iPhone7,2 are the iPhone 6 while iPhone7,3 and iPhone7.4 are the pluses? If anyone has more concrete way to tell it'd be great, thanks.!

Sep 21 in IOS by Soham
• 9,330 points
21 views

1 answer to this question.

0 votes

The device screen will be the first screen, but new phones require launch pictures to be added first; otherwise, older apps will run in Zoomed Mode: The code I used to check this out is shown below. Note that iOS 8 and later is required for this to function.

UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f",
          NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);

Code for detecting iPhone 6 Plus:

#define IS_PAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_PHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

-(BOOL)iPhone6PlusDevice{
    if (!IS_PHONE) return NO;
    if ([UIScreen mainScreen].scale > 2.9) return YES;   // Scale is only 3 when not in scaled mode for iPhone 6 Plus
    return NO;
}

or

-(BOOL) iPhone6PlusUnZoomed{
    if ([self iPhone6PlusDevice]){
        if ([UIScreen mainScreen].bounds.size.height > 720.0) return YES;  // Height is 736, but 667 when zoomed.
    }
    return NO;
}

Relying on.nativeScale will not work if you are adjusting the user interface for the iPhone 6 Plus since the results from the simulator and the actual device differ. because of the remark underneath. Due to the fact that scale is a CGFloat, programmes shouldn't check for equality since some float values may never be equal.

The new iPhone sizes can be used after installing Launch Screen; otherwise, your app will still seem scaled.

updated for the release of the new iPhones 11, 11, Pro, and 11 Pro Max

The physical dimensions of the iPhone 11 Pro Max are 3.06 x 6.22 in (77.8 x 158.0 mm) and 414 x 896 points and 1242 x 2688 pixels, respectively, in coordinate space. Super Retina XDR display of 6.5".

For iPhone, size 11, the physical dimensions of the device are 2.81 x 5.67 in (71.4 x 144.0 mm) and 375 x 812 points and 1125 x 2436 pixels, respectively, with @3x scaling for the 11 Pro. Display size: 5.8" Super Retina XDR.

Size for the iPhone 11 is 2.98 x 5.94 inches (75.7 x 150.9 mm) with @2x scaling, coordinate space: 414 x 896 points and 828 x 1792 pixels, 326 ppi. Liquid Retina HD display, 6.1".

The physical dimensions of the iPhone XS Max are 3.05 x 6.20 in (77.4 x 157.5 mm) with @3x scaling (Apple name: Super Retina HD 6.5 display), coordinate space: 414 x 896 points and 1242 x 2688 pixels, 458 ppi.

let screen = UIScreen.main
print("Screen bounds: \(screen.bounds), Screen resolution: \(screen.nativeBounds), scale: \(screen.scale)")
//iPhone X🅂 Max Screen bounds: (0.0, 0.0, 414.0, 896.0), Screen resolution: (0.0, 0.0, 1242.0, 2688.0), scale: 3.0

The physical dimensions of the iPhone XR are 2.98 x 5.94 in (75.7 x 150.9 mm) with @2x scaling (Apple name: Super Retina HD 6.1" display), coordinate space: 414 x 896 points and 828 x 1792 pixels, 326 ppi.

let screen = UIScreen.main
print("Screen bounds: \(screen.bounds), Screen resolution: \(screen.nativeBounds), scale: \(screen.scale)")
//iPhone X🅁 Screen bounds: (0.0, 0.0, 414.0, 896.0), Screen resolution: (0.0, 0.0, 828.0, 1792.0), scale: 2.0

The physical dimensions of the device are 2.79 x 5.65 in (70.9 x 143.6 mm) for the iPhone XS and iPhone X with @3x scaling (Apple name: Super Retina HD 5.8" display), coordinate space: 375 x 812 points and 1125 x 2436 pixels, 458 ppi.

let screen = UIScreen.main
print("Screen bounds: \(screen.bounds), Screen resolution: \(screen.nativeBounds), scale: \(screen.scale)")
//iPhone X🅂 and X Screen bounds: (0.0, 0.0, 375.0, 812.0), Screen resolution: (0.0, 0.0, 1125.0, 2436.0), scale: 3.0

Screen physical dimension is 2.7 x 4.8 in or 68 x 122 mm for the iPhone 8, 7, 6 Plus, and iPhone 8, 7S Plus with @3x scaling (Apple name: Retina HD 5.5), Coordinate space: 414 x 736 points and 1242 x 2208 pixels, 401 ppi.

Screen bounds: {{0, 0}, {414, 736}}, Screen resolution: <UIScreen: 0x7f97fad330b0; bounds = {{0, 0}, {414, 736}}; 
mode = <UIScreenMode: 0x7f97fae1ce00; size = 1242.000000 x 2208.000000>>, scale: 3.000000, nativeScale: 3.000000

Screen physical dimension is 2.3 x 4.1 in or 58 x 104 mm for the iPhone 6 and iPhone 6S with @2x scaling (Apple name: Retina HD 4.7), Coordinate space: 375 x 667 points and 750 x 1334 pixels, 326 ppi.

Screen bounds: {{0, 0}, {375, 667}}, Screen resolution: <UIScreen: 0x7fa01b5182d0; bounds = {{0, 0}, {375, 667}}; 
mode = <UIScreenMode: 0x7fa01b711760; size = 750.000000 x 1334.000000>>, scale: 2.000000, nativeScale: 2.000000

When compared to the iPhone 4, the iPhone 5 has a resolution of 640 x 1136.

Upload LaunchImages to avoid the programme running scaled and failing to display proper scaling or screen sizes.

Comparing iPhone 6 and 6 Plus

answered Sep 22 by Rahul
• 9,240 points

Related Questions In IOS

0 votes
1 answer

what font face of clock on lock screen of iPhone (iOS 9)?

San Francisco is the default font in ...READ MORE

answered Sep 20 in IOS by Aditya
• 7,660 points
14 views
0 votes
0 answers

How I can open native alarm clock in iphone by using code?

I need to create a sample app ...READ MORE

Sep 22 in IOS by Soham
• 9,330 points
10 views
0 votes
0 answers

Add animated Gif image in Iphone UIImageView

In UIImageview, I must load an animated ...READ MORE

6 days ago in IOS by Soham
• 9,330 points
13 views
0 votes
0 answers

Real iPhone XR screen resolution differs from screen resolution given by swift?

Screenshots, the Apple website, and other sources ...READ MORE

5 days ago in IOS by Soham
• 9,330 points
8 views
0 votes
0 answers

iPhone system font

What is the name of the default ...READ MORE

May 16 in Others by Kichu
• 19,040 points
28 views
0 votes
1 answer

iPhone system font

The iPhone system interface uses Helvetica or ...READ MORE

answered Sep 20 in Others by Aditya
• 7,660 points
19 views
0 votes
1 answer

Getting country calling prefix

For a class that offers both this ...READ MORE

answered Sep 20 in Others by Aditya
• 7,660 points
21 views
0 votes
1 answer

Is there a way to to check if a picture was taken on that iPhone?

Actually, the model and manufacturer information is ...READ MORE

answered Sep 22 in IOS by Rahul
• 9,240 points
16 views
0 votes
1 answer

Can I embed a custom font in an iPhone application?

This is supported by iOS 3.2 and ...READ MORE

answered Sep 22 in IOS by Rahul
• 9,240 points
19 views
0 votes
1 answer

Xcode 12.4 “Unsupported OS version” after iPhone iOS update 14.7

This may only be a short-term fix, ...READ MORE

answered Sep 21 in IOS by Rahul
• 9,240 points
24 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP