How to check if iPad is iPad Pro

15,980

Solution 1

So far this macro seems to do the trick without any issues.

#define IS_IPAD_PRO (MAX([[UIScreen mainScreen]bounds].size.width,[[UIScreen mainScreen] bounds].size.height) > 1024)

Solution 2

+(BOOL) isIpad_1024
{

    if ([UIScreen mainScreen].bounds.size.height == 1024) {
        return  YES;
    }
    return NO;
}

+(BOOL) isIpadPro_1366
{

    if ([UIScreen mainScreen].bounds.size.height == 1366) {
        return  YES;
    }
    return NO;
}

Solution 3

You may use this

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define IS_IPAD_PRO_1366 (IS_IPAD && MAX(SCREEN_WIDTH,SCREEN_HEIGHT) == 1366.0)
#define IS_IPAD_PRO_1024 (IS_IPAD && MAX(SCREEN_WIDTH,SCREEN_HEIGHT) == 1024.0)

Then

 if (IS_IPAD_PRO_1366) {
    NSLog(@"It is ipad pro 1366");
  }

Solution 4

As stated by HAS in their answer here, add this extension in your code:

public extension UIDevice {
    var modelName: String {
        var systemInfo = utsname()
        uname(&systemInfo)
        let machineMirror = Mirror(reflecting: systemInfo.machine)
        let identifier = machineMirror.children.reduce("") { identifier, element in
            guard let value = element.value as? Int8 where value != 0 else { return identifier }
            return identifier + String(UnicodeScalar(UInt8(value)))
        }

        switch identifier {
        case "iPod5,1":                                 return "iPod Touch 5"
        case "iPod7,1":                                 return "iPod Touch 6"
        case "iPhone3,1", "iPhone3,2", "iPhone3,3":     return "iPhone 4"
        case "iPhone4,1":                               return "iPhone 4s"
        case "iPhone5,1", "iPhone5,2":                  return "iPhone 5"
        case "iPhone5,3", "iPhone5,4":                  return "iPhone 5c"
        case "iPhone6,1", "iPhone6,2":                  return "iPhone 5s"
        case "iPhone7,2":                               return "iPhone 6"
        case "iPhone7,1":                               return "iPhone 6 Plus"
        case "iPhone8,1":                               return "iPhone 6s"
        case "iPhone8,2":                               return "iPhone 6s Plus"
        case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4":return "iPad 2"
        case "iPad3,1", "iPad3,2", "iPad3,3":           return "iPad 3"
        case "iPad3,4", "iPad3,5", "iPad3,6":           return "iPad 4"
        case "iPad4,1", "iPad4,2", "iPad4,3":           return "iPad Air"
        case "iPad5,1", "iPad5,3", "iPad5,4":           return "iPad Air 2"
        case "iPad2,5", "iPad2,6", "iPad2,7":           return "iPad Mini"
        case "iPad4,4", "iPad4,5", "iPad4,6":           return "iPad Mini 2"
        case "iPad4,7", "iPad4,8", "iPad4,9":           return "iPad Mini 3"
        case "iPad5,1", "iPad5,2":                      return "iPad Mini 4"
        case "iPad6,7", "iPad6,8":                      return "iPad Pro"
        case "i386", "x86_64":                          return "Simulator"
        default:                                        return identifier
        }
    }
}

And for check

if(UIDevice.currentDevice().modelName == "iPad Pro"){//Your code}

Solution 5

SWIFT

This is the accepted answer written all swift like.

let isIpadPro:Bool = max(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height) > 1024
Share:
15,980
Francis F
Author by

Francis F

I am an iOS developer with over six years’ experience writing highly readable, clean, maintainable source code. I make it my goal to create software with the user in mind, creating applications with a usable and intuitive user interface experience and I also stand for quality. I am constantly striving to learn new technologies and look to ways to better myself in this rapidly changing industry.

Updated on June 17, 2022

Comments

  • Francis F
    Francis F almost 2 years

    The new iPad pro has different dimension and resolutions. If I check based on screen width would it be correct? I havent upgraded to Xcode 7.1 nor do I have the device so I can't check it yet. Will this check work?

    if([UIScreen mainScreen].bounds.size.width>1024)
        {
            // iPad is an iPad Pro
        }
    
  • Leo
    Leo over 8 years
    This will not work.This is the name in settings,user can change the name
  • Divyanshu Sharma
    Divyanshu Sharma over 8 years
    if this is not working then you can manually check your screen height and width like [UIScreen mainScreen].size.height == 2048 then its ipad pro
  • Martin R
    Martin R over 8 years
    This code has been posted repeatedly, e.g. in stackoverflow.com/a/26962452/1187415. If you copy code from another source, please add a link to the original for proper attribution.
  • TahoeWolverine
    TahoeWolverine over 8 years
    What is an iPad Pro 1024? Are you suggesting there are 2 models?
  • FreeNickname
    FreeNickname over 7 years
    I believe, the last line should be MIN, not MAX.
  • Francis F
    Francis F over 7 years
    But this will fail on landscape. At that time for iPad, width is 1024.
  • Ryan Wu
    Ryan Wu almost 4 years
    you missed IS_IPAD