How to check if iPad is iPad Pro

The new iPad has different sizes and resolutions. If I check based on the width of the screen, would it be correct? I have not upgraded to Xcode 7.1, and I don’t have a device, so I can’t check it yet. Will this check work?

if([UIScreen mainScreen].bounds.size.width>1024) { // iPad is an iPad Pro } 
+8
ios objective-c swift xcode7 ipad
source share
13 answers

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

 #define IS_IPAD_PRO (MAX([[UIScreen mainScreen]bounds].size.width,[[UIScreen mainScreen] bounds].size.height) > 1024) 
+5
source share
 +(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; } 
+13
source share

You can 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"); } 
+12
source share

As indicated by HAS in their answer here , add this extension to 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 to check

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

SWIFT

This is an accepted answer, written all quickly as.

 let isIpadPro:Bool = max(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height) > 1024 
+1
source share

Try this library: https://github.com/fahrulazmi/UIDeviceHardware

Then your codes should be:

 NSString *platform = [UIDeviceHardware platformString]; if ([platform isEqualToString:@"iPad6,7"] || [platform isEqualToString:@"iPad6,8"]) { // iPad is an iPad Pro } 

Or this more powerful library: https://github.com/InderKumarRathore/DeviceUtil

The solution may not work for simulators. I want to check the simulator device type, it looks like you need to check the screen size.

0
source share

you can use this code:

 #include <sys/types.h> #include <sys/sysctl.h> - (BOOL) isIpadPro{ 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); if ([platform isEqualToString:@"iPad6,8"]) return YES; return NO; } 
0
source share

Are you guys joking with your complicated answers?

 if([UIScreen mainScreen].bounds.size.width >= 1024) { // iPad pro (or hypothetical/future huge-screened iOS device) } else { // not iPad pro } 

If you just made the> = sign instead of the> sign, it will work wonderfully.

(well, I know that I should not neglect your detailed, specific answers that way. Of course, there are times when a particular device has a larger screen size, but for a quick, obvious answer ...!)

0
source share

This macro works both in landscape and portrait mode:

 #define IS_IPAD_PRO_12_INCH (([UIScreen mainScreen].bounds.size.width == 1366 && [UIScreen mainScreen].bounds.size.height == 1024) || ([UIScreen mainScreen].bounds.size.width == 1024 && [UIScreen mainScreen].bounds.size.height == 1366)) 
0
source share

When I tested the simulator in Xcode 8, none of these solutions worked.

The trick is to look for the height size of "nativeBounds", otherwise you will get 1024 as the height in the simulator

 #define iPadPro12 (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad && UIScreen.mainScreen.nativeBounds.size.height > 1024) if (iPadPro12) { //its ipad Pro 12.9 inch screen } 
0
source share

My complete set of detection devices.

 #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) #define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0) #define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width) #define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height) #define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT)) #define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT)) #define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0) #define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0) #define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0) #define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0) #define IS_IPHONE_X (IS_IPHONE && SCREEN_MAX_LENGTH == 812.0) #define IS_IPAD_PRO_97 (IS_IPAD && SCREEN_MAX_LENGTH == 1024.0) #define IS_IPAD_PRO_105 (IS_IPAD && SCREEN_MAX_LENGTH == 1112.0) #define IS_IPAD_PRO_129 (IS_IPAD && SCREEN_MAX_LENGTH == 1366.0) 
0
source share

Follow the instructions below to verify

 if([[[UIDevice currentDevice] name] isEqualToString:@"iPad Pro"]) { // do your stuff } 
-2
source share

There is a bug for iPad Pro, which currently makes it wrong to use useragent for web browsing. The user agent will look like this:

Mozilla / 5.0 (iPhone, iPhone OS9_1 processor, like Mac OS X) AppleWebKit / 601.1.46 (KHTML, e.g. Gecko) Mobile / 13B143

I think we can use this error to detect iPad Pro for compatible apps.

 -(BOOL)isiPadPro; { UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectZero]; NSString* userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; return [userAgent containsString:@"iPhone"] && ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad); } 
-2
source share

All Articles