Device types in iOS

I sometimes need to know the device type that the app is running on. I use this method in my Utilities class to do it. Updated for the new devices introduced in the fall of 2014.


+ (NSString *)deviceType {
    NSString *device = nil;
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    CGFloat deviceScale = [UIScreen mainScreen].scale;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        device = @"iPhone Classic"; // Just in case it doesn't make it through the conditionals
        // Classic has a resolution of 480 × 320
        if( (screenSize.height == 480 || screenSize.width == 480) && deviceScale == 1.0f ) {
            device = @"iPhone Classic";
        // Retina has a resolution of 960 × 640
        } else if( (screenSize.height == 480 || screenSize.width == 480) && deviceScale == 2.0f ) {
            device = @"iPhone Retina35";
        // Retina 4" has a resolution of 1136 x 640
        } else if (screenSize.height == 568 || screenSize.width == 568 ) {
            device = @"iPhone Retina4";
        // iPhone 6 has a resolution of 1334 by 750
        } else if (screenSize.height == 667 || screenSize.width == 667 ) {
            device = @"iPhone 6";
        // iPhone 6 Plus has a resolution of 1920 by 1080
        // Reported size is 736 x 414
        } else if (screenSize.height == 736 || screenSize.width == 736 ) {
            device = @"iPhone 6 Plus";
        }

    } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        device = @"iPad Classic"; // Just in case it doesn't make it through the conditionals
        if(deviceScale == 1.0f) {
            device = @"iPad Classic";
        } else if (deviceScale == 2.0f) {
            device = @"iPad Retina";
        }
    }
    //NSLog(@"The device is %@ scale is %f and the height is %f and width is %f", device, deviceScale, screenSize.height, screenSize.width);

    return device;
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.