9

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
    }
Francis F
  • 3,157
  • 3
  • 41
  • 79

14 Answers14

14

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");
  }
Leo
  • 24,596
  • 11
  • 71
  • 92
14
+(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;
}
Leo
  • 24,596
  • 11
  • 71
  • 92
pankaj raghav
  • 587
  • 2
  • 9
9

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)
Francis F
  • 3,157
  • 3
  • 41
  • 79
5

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}
Community
  • 1
  • 1
Manuel
  • 1,675
  • 12
  • 18
  • 5
    This code has been posted repeatedly, e.g. in http://stackoverflow.com/a/26962452/1187415. If you copy code from another source, please add a link to the original for proper attribution. – Martin R Nov 20 '15 at 10:25
2

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
Brandon A
  • 8,153
  • 3
  • 42
  • 77
0

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 cannot work for simulators. I you want to check device type of simulator, looks like you have to check the screen size.

Harrison Xi
  • 766
  • 1
  • 5
  • 23
0

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;
}
Jiri Zachar
  • 487
  • 3
  • 8
0

This macro works in both landscape and portrait:

#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))
Jason McClinsey
  • 426
  • 5
  • 12
0

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

The trick is to look for "nativeBounds" size hight otherwise you will keep getting 1024 as height in simulator

#define iPadPro12 (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad && UIScreen.mainScreen.nativeBounds.size.height > 1024)

if (iPadPro12)
{
  //its ipad Pro 12.9 inch screen
}
Sam B
  • 27,273
  • 15
  • 84
  • 121
0

My complete set of device detection.

#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

You can use Regular Expression for detecting iPad in userAgent

var isIPadPro = /Macintosh/.test(navigator.userAgent) && 'ontouchend' in document;
Lesha Petrov
  • 131
  • 1
  • 3
-1

Are you guys joking with your complex answers?

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

If you just did a >= sign instead of a > sign, it will work wonderfully.

(okay, I know I shouldn't be so dismissive of your thorough, specific answers. Surely there are times that specific device matters more than screen size. But for the quick, obvious answer...!)

-2

Follow the below steps for checking

if([[[UIDevice currentDevice] name] isEqualToString:@"iPad Pro"])
{
  //  do your stuff
}
user3182143
  • 9,459
  • 3
  • 32
  • 39
Divyanshu Sharma
  • 551
  • 2
  • 12
  • 2
    This will not work.This is the name in settings,user can change the name – Leo Nov 20 '15 at 06:55
  • 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 – Divyanshu Sharma Nov 20 '15 at 07:20
-2

There is a bug for iPad Pro which make it has a wrong useragent for webview at the moment. User Agent will look likes this:

Mozilla/5.0 (iPhone; CPU iPhone OS9_1 like Mac OS X) AppleWebKit/601.1.46(KHTML, like Gecko)Mobile/13B143

I think we can use this bug for detecting iPad Pro for apps running on compatible mode.

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