About the author

rob@email.null'

Rob

Related Articles

26 Comments

  1. 1
    Gerard

    Gerard Grundy

    Updated platform strings for iPad Air 2 and iPad mini 3:

    - (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:@"iPhone7,1"])    return @"iPhone 6 Plus";
        if ([platform isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
        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:@"iPad4,7"])      return @"iPad mini 3 (WiFi)";
        if ([platform isEqualToString:@"iPad4,8"])      return @"iPad mini 3 (Cellular)";
        if ([platform isEqualToString:@"iPad4,9"])      return @"iPad mini 3 (China Model)";
    
        if ([platform isEqualToString:@"iPad5,3"])      return @"iPad Air 2 (WiFi)";
        if ([platform isEqualToString:@"iPad5,4"])      return @"iPad Air 2 (Cellular)";
        if ([platform isEqualToString:@"iPad6,8"])      return @"iPad Pro";
    
        if ([platform isEqualToString:@"i386"])         return @"Simulator";
        if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
    
        return platform;
    }
    
    Reply
  2. 2
    D1mers0n@email.null'

    D1mers0n

    September 2016: Updated for iPhone 7, iPhone 7 Plus, Apple Watch Series 2

    April 2016: Updated for iPhone 6S, iPhone 6S Plus, iPhone SE, iPad Pro 12.9″, iPad Pro 9.7″, iPad Mini 4, iPod Touch 6G, Apple TV 4, Apple Watch

    Objective-C

    #import <sys/sysctl.h>  
    
    
    -(void)viewDidLoad {   
        [super viewDidLoad];  
    
        size_t size;
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
        char *machine = malloc(size);
        sysctlbyname("hw.machine", machine, &size, NULL, 0);
        NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
        NSLog(@"Device Type ----> %@",[self platformType:platform]);
    
        free(machine);
    }
    
    
    - (NSString *) platformType:(NSString *)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 @"iPhone 4 (Verizon)";
        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:@"iPhone7,2"])    return @"iPhone 6";
        if ([platform isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
        if ([platform isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
        if ([platform isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
        if ([platform isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
        if ([platform isEqualToString:@"iPhone9,1"])    return @"iPhone 7";
        if ([platform isEqualToString:@"iPhone9,3"])    return @"iPhone 7";
        if ([platform isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus";
        if ([platform isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus";
        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:@"iPod7,1"])      return @"iPod Touch 6G";
        if ([platform isEqualToString:@"iPad1,1"])      return @"iPad 1G";
        if ([platform isEqualToString:@"iPad2,1"])      return @"iPad 2 (Wi-Fi)";
        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 (Wi-Fi)";
        if ([platform isEqualToString:@"iPad2,5"])      return @"iPad Mini (Wi-Fi)";
        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 (Wi-Fi)";
        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 (Wi-Fi)";
        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 (Wi-Fi)";
        if ([platform isEqualToString:@"iPad4,2"])      return @"iPad Air (Cellular)";
        if ([platform isEqualToString:@"iPad4,3"])      return @"iPad Air (China)";
        if ([platform isEqualToString:@"iPad4,4"])      return @"iPad Mini 2G (Wi-Fi)";
        if ([platform isEqualToString:@"iPad4,5"])      return @"iPad Mini 2G (Cellular)";
        if ([platform isEqualToString:@"iPad4,6"])      return @"iPad Mini 2G (China)";
        if ([platform isEqualToString:@"iPad4,7"])      return @"iPad Mini 3 (Wi-Fi)";
        if ([platform isEqualToString:@"iPad4,8"])      return @"iPad Mini 3 (Cellular)";
        if ([platform isEqualToString:@"iPad4,9"])      return @"iPad Mini 3 (China)";
        if ([platform isEqualToString:@"iPad5,1"])      return @"iPad Mini 4 (Wi-Fi)";
        if ([platform isEqualToString:@"iPad5,2"])      return @"iPad Mini 4 (Cellular)";
        if ([platform isEqualToString:@"iPad5,3"])      return @"iPad Air 2 (Wi-Fi)";
        if ([platform isEqualToString:@"iPad5,4"])      return @"iPad Air 2 (Cellular)";
        if ([platform isEqualToString:@"iPad6,3"])      return @"iPad Pro 9.7" (Wi-Fi)";
        if ([platform isEqualToString:@"iPad6,4"])      return @"iPad Pro 9.7" (Cellular)";
        if ([platform isEqualToString:@"iPad6,7"])      return @"iPad Pro 12.9" (Wi-Fi)";
        if ([platform isEqualToString:@"iPad6,8"])      return @"iPad Pro 12.9" (Cellular)";
        if ([platform isEqualToString:@"AppleTV2,1"])   return @"Apple TV 2G";
        if ([platform isEqualToString:@"AppleTV3,1"])   return @"Apple TV 3";
        if ([platform isEqualToString:@"AppleTV3,2"])   return @"Apple TV 3 (2013)";
        if ([platform isEqualToString:@"AppleTV5,3"])   return @"Apple TV 4";
        if ([platform isEqualToString:@"Watch1,1"])     return @"Apple Watch Series 1 (38mm, S1)";
        if ([platform isEqualToString:@"Watch1,2"])     return @"Apple Watch Series 1 (42mm, S1)";
        if ([platform isEqualToString:@"Watch2,6"])     return @"Apple Watch Series 1 (38mm, S1P)";
        if ([platform isEqualToString:@"Watch2,7"])     return @"Apple Watch Series 1 (42mm, S1P)";
        if ([platform isEqualToString:@"Watch2,3"])     return @"Apple Watch Series 2 (38mm, S2)";
        if ([platform isEqualToString:@"Watch2,4"])     return @"Apple Watch Series 2 (42mm, S2)";
        if ([platform isEqualToString:@"i386"])         return @"Simulator";
        if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
    
        return platform;
    }
    

    Swift

    (Tested on Swift 2.2)

    override func viewDidLoad() {
        super.viewDidLoad()
        label.text = ""
    
        var sysInfo = utsname()
        uname(&sysInfo)
        let machine = Mirror(reflecting: sysInfo.machine)
        let identifier = machine.children.reduce("") { identifier, element in
            guard let value = element.value as? Int8 where value != 0 else { return identifier }
            return identifier + String(UnicodeScalar(UInt8(value)))
        }
    
        print("Device Type ----> ", self.platformType(identifier))
    }
    
    
    func platformType(platform : NSString) -> NSString {
        if platform.isEqualToString("iPhone1,1")        { return "iPhone 1G" }
        else if platform.isEqualToString("iPhone1,2")   { return "iPhone 3G" }
        else if platform.isEqualToString("iPhone2,1")   { return "iPhone 3GS" }
        else if platform.isEqualToString("iPhone3,1")   { return "iPhone 4" }
        else if platform.isEqualToString("iPhone3,3")   { return "iPhone 4 (Verizon)" }
        else if platform.isEqualToString("iPhone4,1")   { return "iPhone 4S" }
        else if platform.isEqualToString("iPhone5,1")   { return "iPhone 5 (GSM)" }
        else if platform.isEqualToString("iPhone5,2")   { return "iPhone 5 (GSM+CDMA)" }
        else if platform.isEqualToString("iPhone5,3")   { return "iPhone 5c (GSM)" }
        else if platform.isEqualToString("iPhone5,4")   { return "iPhone 5c (GSM+CDMA)" }
        else if platform.isEqualToString("iPhone6,1")   { return "iPhone 5s (GSM)" }
        else if platform.isEqualToString("iPhone6,2")   { return "iPhone 5s (GSM+CDMA)" }
        else if platform.isEqualToString("iPhone7,2")   { return "iPhone 6" }
        else if platform.isEqualToString("iPhone7,1")   { return "iPhone 6 Plus" }
        else if platform.isEqualToString("iPhone8,1")   { return "iPhone 6s" }
        else if platform.isEqualToString("iPhone8,2")   { return "iPhone 6s Plus" }
        else if platform.isEqualToString("iPhone8,4")   { return "iPhone SE" }
        else if platform.isEqualToString("iPhone9,1")   { return "iPhone 7" }
        else if platform.isEqualToString("iPhone9,3")   { return "iPhone 7" }
        else if platform.isEqualToString("iPhone9,2")   { return "iPhone 7 Plus" }
        else if platform.isEqualToString("iPhone9,4")   { return "iPhone 7 Plus" }
        else if platform.isEqualToString("iPod1,1")     { return "iPod Touch 1G" }
        else if platform.isEqualToString("iPod2,1")     { return "iPod Touch 2G" }
        else if platform.isEqualToString("iPod3,1")     { return "iPod Touch 3G" }
        else if platform.isEqualToString("iPod4,1")     { return "iPod Touch 4G" }
        else if platform.isEqualToString("iPod5,1")     { return "iPod Touch 5G" }
        else if platform.isEqualToString("iPod7,1")     { return "iPod Touch 6G" }
        else if platform.isEqualToString("iPad1,1")     { return "iPad 1G" }
        else if platform.isEqualToString("iPad2,1")     { return "iPad 2 (Wi-Fi)" }
        else if platform.isEqualToString("iPad2,2")     { return "iPad 2 (GSM)" }
        else if platform.isEqualToString("iPad2,3")     { return "iPad 2 (CDMA)" }
        else if platform.isEqualToString("iPad2,4")     { return "iPad 2 (Wi-Fi)" }
        else if platform.isEqualToString("iPad2,5")     { return "iPad Mini (Wi-Fi)" }
        else if platform.isEqualToString("iPad2,6")     { return "iPad Mini (GSM)" }
        else if platform.isEqualToString("iPad2,7")     { return "iPad Mini (GSM+CDMA)" }
        else if platform.isEqualToString("iPad3,1")     { return "iPad 3 (Wi-Fi)" }
        else if platform.isEqualToString("iPad3,2")     { return "iPad 3 (GSM+CDMA)" }
        else if platform.isEqualToString("iPad3,3")     { return "iPad 3 (GSM)" }
        else if platform.isEqualToString("iPad3,4")     { return "iPad 4 (Wi-Fi)"}
        else if platform.isEqualToString("iPad3,5")     { return "iPad 4 (GSM)" }
        else if platform.isEqualToString("iPad3,6")     { return "iPad 4 (GSM+CDMA)" }
        else if platform.isEqualToString("iPad4,1")     { return "iPad Air (Wi-Fi)" }
        else if platform.isEqualToString("iPad4,2")     { return "iPad Air (Cellular)" }
        else if platform.isEqualToString("iPad4,3")     { return "iPad Air (China)" }
        else if platform.isEqualToString("iPad4,4")     { return "iPad Mini 2G (Wi-Fi)" }
        else if platform.isEqualToString("iPad4,5")     { return "iPad Mini 2G (Cellular)" }
        else if platform.isEqualToString("iPad4,6")     { return "iPad Mini 2G (China)" }
        else if platform.isEqualToString("iPad4,7")     { return "iPad Mini 3 (Wi-Fi)" }
        else if platform.isEqualToString("iPad4,8")     { return "iPad Mini 3 (Cellular)" }
        else if platform.isEqualToString("iPad4,9")     { return "iPad Mini 3 (China)" }
        else if platform.isEqualToString("iPad5,1")     { return "iPad Mini 4 (Wi-Fi)" }
        else if platform.isEqualToString("iPad5,2")     { return "iPad Mini 4 (Cellular)" }
        else if platform.isEqualToString("iPad5,3")     { return "iPad Air 2 (Wi-Fi)" }
        else if platform.isEqualToString("iPad5,4")     { return "iPad Air 2 (Cellular)" }
        else if platform.isEqualToString("iPad6,3")     { return "iPad Pro 9.7" (Wi-Fi)" }
        else if platform.isEqualToString("iPad6,4")     { return "iPad Pro 9.7" (Cellular)" }
        else if platform.isEqualToString("iPad6,7")     { return "iPad Pro 12.9" (Wi-Fi)" }
        else if platform.isEqualToString("iPad6,8")     { return "iPad Pro 12.9" (Cellular)" }
        else if platform.isEqualToString("AppleTV2,1")  { return "Apple TV 2G" }
        else if platform.isEqualToString("AppleTV3,1")  { return "Apple TV 3" }
        else if platform.isEqualToString("AppleTV3,2")  { return "Apple TV 3 (2013)" }
        else if platform.isEqualToString("AppleTV5,3")  { return "Apple TV 4" }
        else if platform.isEqualToString("Watch1,1")    { return "Apple Watch Series 1 (38mm, S1)" }
        else if platform.isEqualToString("Watch1,2")    { return "Apple Watch Series 1 (42mm, S1)" }
        else if platform.isEqualToString("Watch2,6")    { return "Apple Watch Series 1 (38mm, S1P)" }
        else if platform.isEqualToString("Watch2,7")    { return "Apple Watch Series 1 (42mm, S1P)" }
        else if platform.isEqualToString("Watch2,3")    { return "Apple Watch Series 2 (38mm, S2)" }
        else if platform.isEqualToString("Watch2,4")    { return "Apple Watch Series 2 (42mm, S2)" }
        else if platform.isEqualToString("i386")        { return "Simulator" }
        else if platform.isEqualToString("x86_64")      { return "Simulator"}
    
        return platform
    }
    
    Reply
  3. 3
    Brian

    Brian Robbins

    This is an update for UIDeviceHardware.m from the answer above.

    - (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:@"iPhone7,1"])    return @"iPhone 6";
        if ([platform isEqualToString:@"iPhone7,2"])    return @"iPhone 6 Plus";
        if ([platform isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
        if ([platform isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
        if ([platform isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
        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:@"iPod7,1"])      return @"iPod Touch 6G";
        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:@"iPad5,1"])      return @"iPad mini 4 (WiFi)";
        if ([platform isEqualToString:@"iPad5,2"])      return @"iPad mini 4 (Cellular)";
        if ([platform isEqualToString:@"iPad5,3"])      return @"iPad Air 2 (WiFi)";
        if ([platform isEqualToString:@"iPad5,4"])      return @"iPad Air 2 (Cellular)";
        if ([platform isEqualToString:@"iPad6,3"])      return @"iPad Pro 9.7 inch (WiFi)";
        if ([platform isEqualToString:@"iPad6,4"])      return @"iPad Pro 9.7 inch (Cellular)";
        if ([platform isEqualToString:@"iPad6,7"])      return @"iPad Pro 12.9 inch (WiFi)";
        if ([platform isEqualToString:@"iPad6,8"])      return @"iPad Pro 12.9 inch (Cellular)";
        if ([platform isEqualToString:@"i386"])         return @"Simulator";
        if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
    
        return platform;
    }
    
    Reply
  4. 4
    Salim@email.null'

    Salim

    #import <sys/utsname.h> 
    
    NSString *iPhone = [self iPhoneVersion]; 
    
    -(NSString*)iPhoneVersion
    {
       NSString *platform;
       struct utsname systemInfo;
       uname(&systemInfo);
       platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
       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 @"VerizoniPhone 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:@"iPhone7,2"])    return @"iPhone 6";
       if ([platform isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
       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,3"])      return @"iPad Air";
       if ([platform isEqualToString:@"iPad4,4"])      return @"iPad Mini 2G (WiFi)";
       if ([platform isEqualToString:@"iPad4,5"])      return @"iPad Mini 2G (Cellular)";
       if ([platform isEqualToString:@"iPad4,6"])      return @"iPad Mini 2G";
       if ([platform isEqualToString:@"iPad4,7"])      return @"iPad Mini 3 (WiFi)";
       if ([platform isEqualToString:@"iPad4,8"])      return @"iPad Mini 3 (Cellular)";
       if ([platform isEqualToString:@"iPad4,9"])      return @"iPad Mini 3 (China)";
       if ([platform isEqualToString:@"iPad5,3"])      return @"iPad Air 2 (WiFi)";
       if ([platform isEqualToString:@"iPad5,4"])      return @"iPad Air 2 (Cellular)";
       if ([platform isEqualToString:@"AppleTV2,1"])   return @"Apple TV 2G";
       if ([platform isEqualToString:@"AppleTV3,1"])   return @"Apple TV 3";
       if ([platform isEqualToString:@"AppleTV3,2"])   return @"Apple TV 3 (2013)";
       if ([platform isEqualToString:@"i386"])         return @"Simulator";
       if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
       return platform;
    }
    
    Reply
  5. 5
    Inder

    Inder Kumar Rathore

    The possible vales of

    [[UIDevice currentDevice] model];
    

    are iPod touch, iPhone, iPhone Simulator, iPad, iPad Simulator

    If you want to know which hardware iOS is ruining on like iPhone3, iPhone4, iPhone5 etc below is the code for that


    NOTE: The below code may not contain all device’s string, I’m with other guys are maintaining the same code on GitHub so please take the latest code from there

    Objective-C : GitHub/DeviceUtil

    Swift : GitHub/DeviceGuru


    #include <sys/types.h>
    #include <sys/sysctl.h>
    
    - (NSString*)hardwareDescription {
        NSString *hardware = [self hardwareString];
        if ([hardware isEqualToString:@"iPhone1,1"]) return @"iPhone 2G";
        if ([hardware isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
        if ([hardware isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
        if ([hardware isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
        if ([hardware isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
        if ([hardware isEqualToString:@"iPod1,1"]) return @"iPodTouch 1G";
        if ([hardware isEqualToString:@"iPod2,1"]) return @"iPodTouch 2G";
        if ([hardware isEqualToString:@"iPad1,1"]) return @"iPad";
        if ([hardware isEqualToString:@"iPad2,6"]) return @"iPad Mini";
        if ([hardware isEqualToString:@"iPad4,1"]) return @"iPad Air WIFI";
        //there are lots of other strings too, checkout the github repo
        //link is given at the top of this answer
    
        if ([hardware isEqualToString:@"i386"]) return @"Simulator";
        if ([hardware isEqualToString:@"x86_64"]) return @"Simulator";
    
        return nil;
    }
    
    - (NSString*)hardwareString {
        size_t size = 100;
        char *hw_machine = malloc(size);
        int name[] = {CTL_HW,HW_MACHINE};
        sysctl(name, 2, hw_machine, &size, NULL, 0);
        NSString *hardware = [NSString stringWithUTF8String:hw_machine];
        free(hw_machine);
        return hardware;
    }
    
    Reply
  6. 6
    Maxim

    Maxim Pavlov

    You can check GBDeviceInfo on GitHub, also available via CocoaPods. It provides simple API for detecting various properties with support of all latest devices:

    • Device family

    [GBDeviceInfo deviceDetails].family == GBDeviceFamilyiPhone;

    • Device model

    [GBDeviceInfo deviceDetails].model == GBDeviceModeliPhone6.

    For more see Readme.

    Reply
  7. 7
    GJDK@email.null'

    GJDK

    NSString *deviceType = [[UIDevice currentDevice] systemName];
    

    I can assure that the above suggested one will work in iOS 7 and above. I believe it will work in iOS 6 too. But am not sure about that.

    Reply
  8. 8
    Adam

    Adam Rosenfield

    You can use the UIDevice class like this:

    NSString *deviceType = [UIDevice currentDevice].model;
    
    if([deviceType isEqualToString:@"iPhone"])
        // it's an iPhone
    
    Reply
  9. 9
    Jayprakash

    Jayprakash Dubey

    Below mentioned code snippet should help :

     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
       // iPhone device
     }
     else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
       // iPad device
     }
     else {
      // Other device i.e. iPod
     }
    
    Reply
  10. 10
    Ortwin

    Ortwin Gentz

    I’d like to add that to retrieve the front and enclosure color of the device there’s a private API:

    UIDevice *device = [UIDevice currentDevice];
    SEL selector = NSSelectorFromString([device.systemVersion hasPrefix:@"7"] ? @"_deviceInfoForKey:" :  @"deviceInfoForKey:");
    if ([device respondsToSelector:selector]) {
        NSLog(@"DeviceColor: %@ DeviceEnclosureColor: %@", [device performSelector:selector withObject:@"DeviceColor"], [device performSelector:selector withObject:@"DeviceEnclosureColor"]);
    }
    

    I’ve blogged about this and provide a sample app:

    http://www.futuretap.com/blog/device-colors/

    Reply
  11. 11
    Dan

    Dan Loughney

    I took it a bit further and converted the big “isEqualToString” block into a classification of bit masks for the device type, the generation, and that other qualifier after the comma (I’m calling it the sub generation). It is wrapped in a class with a singleton call SGPlatform which avoids a lot of repetitive string operations. Code is available https://github.com/danloughney/spookyGroup

    The class lets you do things like this:

    if ([SGPlatform iPad] && [SGPlatform generation] > 3) {
        // set for high performance
    }
    

    and

    switch ([SGPlatform deviceMask]) {
    case DEVICE_IPHONE:
        break;
    case DEVICE_IPAD:
        break;
    case DEVICE_IPAD_MINI:
        break;
    }
    

    The classification of the devices is in the platformBits method. That method should be very familiar to the readers of this thread. I have classified the devices by their type and generation because I’m mostly interested in the overall performance, but the source can be tweaked to provide any classification that you are interested in, retina screen, networking capabilities, etc..

    Reply
  12. 12
    Bhavesh

    Bhavesh Nayi

    NSString *deviceType = [UIDevice currentDevice].model;
    
    Reply
  13. 13
    QED@email.null'

    QED

    I like Erica Sadun’s stuff. She includes AppleTV devices and others you might not think of.

    https://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.h

    Reply
  14. 14
    Gurpreet

    Gurpreet Singh

    if([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad) {
        //Device is ipad 
    }else{
        //Device is iphone
    }
    
    Reply
  15. 15
    David

    David DelMonte

    Adding to Arash’s code, I don’t care for my app what model I’m using, I just want to know what kind of device, so, I can test as follows:

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
            {
                NSLog(@"I'm definitely an iPad");
        } else {
        NSString *deviceType = [UIDevice currentDevice].model;
                    if([deviceType rangeOfString:@"iPhone"].location!=NSNotFound)
                    {
                        NSLog(@"I must be an iPhone");
    
                    } else {
                        NSLog(@"I think I'm an iPod");
    
                    }
    }
    
    Reply
  16. 16
    Arash

    Arash Zeinoddini

    - (BOOL)deviceiPhoneOriPod
      {
        NSString *deviceType = [UIDevice currentDevice].model;
        if([deviceType rangeOfString:@"iPhone"].location!=NSNotFound)
          return YES;
        else
          return NO;
      }
    
    Reply
  17. 17
    Rodrigo@email.null'

    Rodrigo

    How about this code, if new version was released, you will identifier with the last know device

    - (NSString *)getModel {
        size_t size;
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
        char *model = malloc(size);
        sysctlbyname("hw.machine", model, &size, NULL, 0);
        NSString *sDeviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
        free(model);                              
        if ([sDeviceModel isEqual:@"i386"])      return @"Simulator";  //iPhone Simulator
        if ([sDeviceModel isEqual:@"iPhone1,1"]) return @"iPhone1G";   //iPhone 1G
        if ([sDeviceModel isEqual:@"iPhone1,2"]) return @"iPhone3G";   //iPhone 3G
        if ([sDeviceModel isEqual:@"iPhone2,1"]) return @"iPhone3GS";  //iPhone 3GS
        if ([sDeviceModel isEqual:@"iPhone3,1"]) return @"iPhone3GS";  //iPhone 4 - AT&T
        if ([sDeviceModel isEqual:@"iPhone3,2"]) return @"iPhone3GS";  //iPhone 4 - Other carrier
        if ([sDeviceModel isEqual:@"iPhone3,3"]) return @"iPhone4";    //iPhone 4 - Other carrier
        if ([sDeviceModel isEqual:@"iPhone4,1"]) return @"iPhone4S";   //iPhone 4S
        if ([sDeviceModel isEqual:@"iPod1,1"])   return @"iPod1stGen"; //iPod Touch 1G
        if ([sDeviceModel isEqual:@"iPod2,1"])   return @"iPod2ndGen"; //iPod Touch 2G
        if ([sDeviceModel isEqual:@"iPod3,1"])   return @"iPod3rdGen"; //iPod Touch 3G
        if ([sDeviceModel isEqual:@"iPod4,1"])   return @"iPod4thGen"; //iPod Touch 4G
        if ([sDeviceModel isEqual:@"iPad1,1"])   return @"iPadWiFi";   //iPad Wifi
        if ([sDeviceModel isEqual:@"iPad1,2"])   return @"iPad3G";     //iPad 3G
        if ([sDeviceModel isEqual:@"iPad2,1"])   return @"iPad2";      //iPad 2 (WiFi)
        if ([sDeviceModel isEqual:@"iPad2,2"])   return @"iPad2";      //iPad 2 (GSM)
        if ([sDeviceModel isEqual:@"iPad2,3"])   return @"iPad2";      //iPad 2 (CDMA)
    
        NSString *aux = [[sDeviceModel componentsSeparatedByString:@","] objectAtIndex:0];
    
    //If a newer version exist
        if ([aux rangeOfString:@"iPhone"].location!=NSNotFound) {
            int version = [[aux stringByReplacingOccurrencesOfString:@"iPhone" withString:@""] intValue];
            if (version == 3) return @"iPhone4"
            if (version >= 4) return @"iPhone4s";
    
        }
        if ([aux rangeOfString:@"iPod"].location!=NSNotFound) {
            int version = [[aux stringByReplacingOccurrencesOfString:@"iPod" withString:@""] intValue];
            if (version >=4) return @"iPod4thGen";
        }
        if ([aux rangeOfString:@"iPad"].location!=NSNotFound) {
            int version = [[aux stringByReplacingOccurrencesOfString:@"iPad" withString:@""] intValue];
            if (version ==1) return @"iPad3G";
            if (version >=2) return @"iPad2";
        }
        //If none was found, send the original string
        return sDeviceModel;
    }
    
    Reply
  18. 18
    UIBuilder@email.null'

    UIBuilder

    More usable

    #include <sys/types.h>
    #include <sys/sysctl.h>
    
    @interface UIDevice(Hardware)
    
    - (NSString *) platform;
    
    - (BOOL)hasRetinaDisplay;
    
    - (BOOL)hasMultitasking;
    
    - (BOOL)hasCamera;
    
    @end
    
    @implementation UIDevice(Hardware)
    
    - (NSString *) platform{
        int mib[2];
    size_t len;
    char *machine;
    
    mib[0] = CTL_HW;
    mib[1] = HW_MACHINE;
    sysctl(mib, 2, NULL, &len, NULL, 0);
    machine = malloc(len);
    sysctl(mib, 2, machine, &len, NULL, 0);
    
        NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
        free(machine);
    return platform;
    }
    
    - (BOOL)hasRetinaDisplay {
        NSString *platform = [self platform];
        BOOL ret = YES;
        if ([platform isEqualToString:@"iPhone1,1"]) {
            ret = NO;
        }
        else
            if ([platform isEqualToString:@"iPhone1,2"])    ret = NO;
        else 
            if ([platform isEqualToString:@"iPhone2,1"])    ret = NO;
        else 
            if ([platform isEqualToString:@"iPod1,1"])      ret = NO;
        else
            if ([platform isEqualToString:@"iPod2,1"])      ret = NO;
        else
            if ([platform isEqualToString:@"iPod3,1"])      ret = NO;
        return ret;
    }
    
    - (BOOL)hasMultitasking {
        if ([self respondsToSelector:@selector(isMultitaskingSupported)]) {
            return [self isMultitaskingSupported];
        }
        return NO;
    }
    
    - (BOOL)hasCamera {
       BOOL ret = NO;
       // check camera availability
       return ret;
    }
    
    @end
    

    you can reading properties with

    NSLog(@"platform %@, retita %@, multitasking %@", [[UIDevice currentDevice] platform], [[UIDevice currentDevice] hasRetinaDisplay] ? @"YES" : @"NO" , [[UIDevice currentDevice] hasMultitasking] ? @"YES" : @"NO");
    
    Reply
  19. 19
    snibbe@email.null'

    snibbe

    Here’s a minor update with new models:

    - (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:@"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:@"i386"])   return @"iPhone Simulator";
        return platform;
    }
    
    Reply
  20. 20
    Tomasz@email.null'

    Tomasz

    I use this in my app. Up to date as of December 2012.

    - (NSString *) platformString {
        // Gets a string with the device model
        size_t size;  
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);  
        char *machine = malloc(size);  
        sysctlbyname("hw.machine", machine, &size, NULL, 0);  
        NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];  
        free(machine); 
    
        if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 2G";
        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,2"])    return @"iPhone 4";
        if ([platform isEqualToString:@"iPhone3,3"])    return @"iPhone 4 (CDMA)";    
        if ([platform isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
        if ([platform isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
        if ([platform isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (GSM+CDMA)";
    
        if ([platform isEqualToString:@"iPod1,1"])      return @"iPod Touch (1 Gen)";
        if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch (2 Gen)";
        if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch (3 Gen)";
        if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch (4 Gen)";
        if ([platform isEqualToString:@"iPod5,1"])      return @"iPod Touch (5 Gen)";
    
        if ([platform isEqualToString:@"iPad1,1"])      return @"iPad";
        if ([platform isEqualToString:@"iPad1,2"])      return @"iPad 3G";
        if ([platform isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
        if ([platform isEqualToString:@"iPad2,2"])      return @"iPad 2";
        if ([platform isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
        if ([platform isEqualToString:@"iPad2,4"])      return @"iPad 2";
        if ([platform isEqualToString:@"iPad2,5"])      return @"iPad Mini (WiFi)";
        if ([platform isEqualToString:@"iPad2,6"])      return @"iPad Mini";
        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";
        if ([platform isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
        if ([platform isEqualToString:@"iPad3,5"])      return @"iPad 4";
        if ([platform isEqualToString:@"iPad3,6"])      return @"iPad 4 (GSM+CDMA)";
    
        if ([platform isEqualToString:@"i386"])         return @"Simulator";
        if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
    
        return platform;
    }  
    
    Reply
  21. 21
    user4657588@email.null'

    user4657588

    I know an answer has been ticked already, but for future reference, you could always use the device screen size to figure out which device it is like so:

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    
        CGSize result = [[UIScreen mainScreen] bounds].size;
    
        if (result.height == 480) {
            // 3.5 inch display - iPhone 4S and below
            NSLog(@"Device is an iPhone 4S or below");
        }
    
        else if (result.height == 568) {
            // 4 inch display - iPhone 5
            NSLog(@"Device is an iPhone 5/S/C");
        }
    
        else if (result.height == 667) {
            // 4.7 inch display - iPhone 6
            NSLog(@"Device is an iPhone 6");
        }
    
        else if (result.height == 736) {
            // 5.5 inch display - iPhone 6 Plus
            NSLog(@"Device is an iPhone 6 Plus");
        }
    } 
    
    else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
           // iPad 9.7 or 7.9 inch display.
           NSLog(@"Device is an iPad.");
    }
    
    Reply
  22. 22
    Dutchie432@email.null'

    Dutchie432

    Please feel free to use this class (gist @ github)

    CODE REMOVED AND RELOCATED TO

    https://gist.github.com/1323251

    UPDATE (01/14/11)

    Obviously, this code is a bit out of date by now, but it can certainly be updated using the code on this thread provided by Brian Robbins which includes similar code with updated models. Thanks for the support on this thread.

    Reply
  23. 23
    benvolioT@email.null'

    benvolioT

    Based on the very good answers above, here is what I came up with. This is very similar to @Rodrigo’s answer, but addresses @Oliver’s concern from the comment on that answer. This also provides the option of including the model string in the output string.

    + (NSString *) deviceModel {
        size_t size;
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
        char *model = malloc(size);
        sysctlbyname("hw.machine", model, &size, NULL, 0);
        NSString *deviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
        free(model);      
    
        return deviceModel;
    }
    
    + (NSString *) deviceName {
        NSString *deviceModel = [DeviceGateway deviceModel];                    
    
        if ([deviceModel isEqual:@"i386"])      return @"Simulator";  //iPhone Simulator
        if ([deviceModel isEqual:@"iPhone1,1"]) return @"iPhone1G";   //iPhone 1G
        if ([deviceModel isEqual:@"iPhone1,2"]) return @"iPhone3G";   //iPhone 3G
        if ([deviceModel isEqual:@"iPhone2,1"]) return @"iPhone3GS";  //iPhone 3GS
        if ([deviceModel isEqual:@"iPhone3,1"]) return @"iPhone4";    //iPhone 4 - AT&T
        if ([deviceModel isEqual:@"iPhone3,2"]) return @"iPhone4";    //iPhone 4 - Other carrier
        if ([deviceModel isEqual:@"iPhone3,3"]) return @"iPhone4";    //iPhone 4 - Other carrier
        if ([deviceModel isEqual:@"iPhone4,1"]) return @"iPhone4S";   //iPhone 4S
        if ([deviceModel isEqual:@"iPod1,1"])   return @"iPod1stGen"; //iPod Touch 1G
        if ([deviceModel isEqual:@"iPod2,1"])   return @"iPod2ndGen"; //iPod Touch 2G
        if ([deviceModel isEqual:@"iPod3,1"])   return @"iPod3rdGen"; //iPod Touch 3G
        if ([deviceModel isEqual:@"iPod4,1"])   return @"iPod4thGen"; //iPod Touch 4G
        if ([deviceModel isEqual:@"iPad1,1"])   return @"iPadWiFi";   //iPad Wifi
        if ([deviceModel isEqual:@"iPad1,2"])   return @"iPad3G";     //iPad 3G
        if ([deviceModel isEqual:@"iPad2,1"])   return @"iPad2";      //iPad 2 (WiFi)
        if ([deviceModel isEqual:@"iPad2,2"])   return @"iPad2";      //iPad 2 (GSM)
        if ([deviceModel isEqual:@"iPad2,3"])   return @"iPad2";      //iPad 2 (CDMA)
    
        NSString *aux = [[deviceModel componentsSeparatedByString:@","] objectAtIndex:0];
    
        //If a newer version exists
        if ([aux rangeOfString:@"iPhone"].location != NSNotFound) {
            int version = [[aux stringByReplacingOccurrencesOfString:@"iPhone" withString:@""] intValue];
            if (version == 3) return @"iPhone4";
            if (version == 4) return @"iPhone4s";
            return @"Newer iPhone";
        }
        if ([aux rangeOfString:@"iPod"].location != NSNotFound) {
            int version = [[aux stringByReplacingOccurrencesOfString:@"iPod" withString:@""] intValue];
            if (version == 4) return @"iPod4thGen";
            return @"Newer iPod";
        }
        if ([aux rangeOfString:@"iPad"].location != NSNotFound) {
            int version = [[aux stringByReplacingOccurrencesOfString:@"iPad" withString:@""] intValue];
            if (version == 1) return @"iPad3G";
            if (version == 2) return @"iPad2";
            return @"Newer iPad";
        }
    
        //If none was found, send the original string
        return deviceModel;
    }
    
    + (NSString *) deviceNameWithDeviceModel:(BOOL)shouldIncludeDeviceModel {
        if (shouldIncludeDeviceModel) {
            return [NSString stringWithFormat:@"%@ (%@)", [DeviceGateway deviceName], [DeviceGateway deviceModel]];
        }
    
        return [DeviceGateway deviceName];
    }
    
    Reply
  24. 24
    Sebyddd@email.null'

    Sebyddd

    There’s a pretty mature library (by me) for that called SDVersion.
    You can check for running device’s model, screen size and many other parameters. It also supports OSX.

    Example:

          // Check for device model
          if ([SDVersion deviceVersion] == iPhone6)
               NSLog(@"You got the iPhone 6. Sweet 🍭!");
          else if ([SDVersion deviceVersion] == iPhone6Plus)
               NSLog(@"iPhone 6 Plus? Bigger is better!");
          else if ([SDVersion deviceVersion] == iPadAir2)
               NSLog(@"You own an iPad Air 2 🌀!");
    
          // Check for device screen size
          if ([SDVersion deviceSize] == Screen4inch)
               NSLog(@"Your screen is 4 inches");
    
    Reply
  25. 25
    Di

    Di Wu

    Dutchie432 and Brian Robbins have provided great solutions. But there’s still one model missing, the Verizon iPhone 4. Here’s the missing line.

    if ([platform isEqualToString:@"iPhone3,2"])    return @"iPhone 4"; //Verizon
    
    Reply
  26. 26
    Jason

    Jason Fuerstenberg

    Just adding the iPhone 4S device code to this thread…

    The iPhone 4S will return the string @”iPhone4,1″.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2017 SolutionMmyself.com