How to get device make and model on iOS?

后端 未结 19 977
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 04:58

I was wondering if it\'s possible to determine what kind of iPhone (for example) the currentdevice is? I know it\'s possible to get the model through
NSString

相关标签:
19条回答
  • 2020-11-22 05:24

    A category for going getting away from the NSString description

    In general, it is desirable to avoid arbitrary string comparisons throughout your code. It is better to update the strings in one place and hide the magic string from your app. I provide a category on UIDevice for that purpose.

    For my specific needs I need to know which device I am using without the need to know specifics about networking capability that can be easily retrieved in other ways. So you will find a coarser grained enum than the ever growing list of devices.

    Updating is a matter of adding the device to the enum and the lookup table.

    UIDevice+NTNUExtensions.h

    typedef NS_ENUM(NSUInteger, NTNUDeviceType) {
        DeviceAppleUnknown,
        DeviceAppleSimulator,
        DeviceAppleiPhone,
        DeviceAppleiPhone3G,
        DeviceAppleiPhone3GS,
        DeviceAppleiPhone4,
        DeviceAppleiPhone4S,
        DeviceAppleiPhone5,
        DeviceAppleiPhone5C,
        DeviceAppleiPhone5S,
        DeviceAppleiPhone6,
        DeviceAppleiPhone6_Plus,
        DeviceAppleiPhone6S,
        DeviceAppleiPhone6S_Plus,
        DeviceAppleiPhoneSE,
        DeviceAppleiPhone7,
        DeviceAppleiPhone7_Plus,
        DeviceAppleiPodTouch,
        DeviceAppleiPodTouch2G,
        DeviceAppleiPodTouch3G,
        DeviceAppleiPodTouch4G,
        DeviceAppleiPad,
        DeviceAppleiPad2,
        DeviceAppleiPad3G,
        DeviceAppleiPad4G,
        DeviceAppleiPad5G_Air,
        DeviceAppleiPadMini,
        DeviceAppleiPadMini2G,
        DeviceAppleiPadPro12,
        DeviceAppleiPadPro9
    };
    
    
    
    @interface UIDevice (NTNUExtensions)
    
    - (NSString *)ntnu_deviceDescription;
    - (NTNUDeviceType)ntnu_deviceType;
    
    @end
    

    UIDevice+NTNUExtensions.m

    #import <sys/utsname.h>
    #import "UIDevice+NTNUExtensions.h"
    
    @implementation UIDevice (NTNUExtensions)
    
    - (NSString *)ntnu_deviceDescription
    {
        struct utsname systemInfo;
        uname(&systemInfo);
    
        return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    }
    
    - (NTNUDeviceType)ntnu_deviceType
    {
        NSNumber *deviceType = [[self ntnu_deviceTypeLookupTable] objectForKey:[self ntnu_deviceDescription]];
        return [deviceType unsignedIntegerValue];
    }
    
    - (NSDictionary *)ntnu_deviceTypeLookupTable
    {
        return @{
                 @"i386": @(DeviceAppleSimulator),
                 @"x86_64": @(DeviceAppleSimulator),
                 @"iPod1,1": @(DeviceAppleiPodTouch),
                 @"iPod2,1": @(DeviceAppleiPodTouch2G),
                 @"iPod3,1": @(DeviceAppleiPodTouch3G),
                 @"iPod4,1": @(DeviceAppleiPodTouch4G),
                 @"iPhone1,1": @(DeviceAppleiPhone),
                 @"iPhone1,2": @(DeviceAppleiPhone3G),
                 @"iPhone2,1": @(DeviceAppleiPhone3GS),
                 @"iPhone3,1": @(DeviceAppleiPhone4),
                 @"iPhone3,3": @(DeviceAppleiPhone4),
                 @"iPhone4,1": @(DeviceAppleiPhone4S),
                 @"iPhone5,1": @(DeviceAppleiPhone5),
                 @"iPhone5,2": @(DeviceAppleiPhone5),
                 @"iPhone5,3": @(DeviceAppleiPhone5C),
                 @"iPhone5,4": @(DeviceAppleiPhone5C),
                 @"iPhone6,1": @(DeviceAppleiPhone5S),
                 @"iPhone6,2": @(DeviceAppleiPhone5S),
                 @"iPhone7,1": @(DeviceAppleiPhone6_Plus),
                 @"iPhone7,2": @(DeviceAppleiPhone6),
                 @"iPhone8,1" :@(DeviceAppleiPhone6S),
                 @"iPhone8,2" :@(DeviceAppleiPhone6S_Plus),
                 @"iPhone8,4" :@(DeviceAppleiPhoneSE),
                 @"iPhone9,1" :@(DeviceAppleiPhone7),
                 @"iPhone9,3" :@(DeviceAppleiPhone7),
                 @"iPhone9,2" :@(DeviceAppleiPhone7_Plus),
                 @"iPhone9,4" :@(DeviceAppleiPhone7_Plus),
                 @"iPad1,1": @(DeviceAppleiPad),
                 @"iPad2,1": @(DeviceAppleiPad2),
                 @"iPad3,1": @(DeviceAppleiPad3G),
                 @"iPad3,4": @(DeviceAppleiPad4G),
                 @"iPad2,5": @(DeviceAppleiPadMini),
                 @"iPad4,1": @(DeviceAppleiPad5G_Air),
                 @"iPad4,2": @(DeviceAppleiPad5G_Air),
                 @"iPad4,4": @(DeviceAppleiPadMini2G),
                 @"iPad4,5": @(DeviceAppleiPadMini2G),
                 @"iPad4,7":@(DeviceAppleiPadMini),
                 @"iPad6,7":@(DeviceAppleiPadPro12),
                 @"iPad6,8":@(DeviceAppleiPadPro12),
                 @"iPad6,3":@(DeviceAppleiPadPro9),
                 @"iPad6,4":@(DeviceAppleiPadPro9)
                 };
    }
    
    @end
    
    0 讨论(0)
  • 2020-11-22 05:24

    Below Function Perfectly Working on iOS7 or later version in Swift

    func DeviceName()-> String {
    
            var myDeviceName : String = String()
    
            var systemInfo = [UInt8](count: sizeof(utsname), repeatedValue: 0)
    
            let model = systemInfo.withUnsafeMutableBufferPointer { (inout body: UnsafeMutableBufferPointer<UInt8>) -> String? in
    
                if uname(UnsafeMutablePointer(body.baseAddress)) != 0 {
                    return nil
                }
    
                return String.fromCString(UnsafePointer(body.baseAddress.advancedBy(Int(_SYS_NAMELEN * 4))))
            }
    
            let deviceNamesByCode : [String: String] = ["iPod1,1":"iPod Touch 1",
                                                        "iPod2,1":"iPod Touch 2",
                                                        "iPod3,1":"iPod Touch 3",
                                                        "iPod4,1":"iPod Touch 4",
                                                        "iPod5,1":"iPod Touch 5",
                                                        "iPod7,1":"iPod Touch 6",
                                                        "iPhone1,1":"iPhone",
                                                        "iPhone1,2":"iPhone ",
                                                        "iPhone2,1":"iPhone ",
                                                        "iPhone3,1":"iPhone 4",
                                                        "iPhone3,2":"iPhone 4",
                                                        "iPhone3,3":"iPhone 4",
                                                        "iPhone4,1":"iPhone 4s",
                                                        "iPhone5,1":"iPhone 5",
                                                        "iPhone5,2":"iPhone 5",
                                                        "iPhone5,3":"iPhone 5c",
                                                        "iPhone5,4":"iPhone 5c",
                                                        "iPhone6,1":"iPhone 5s",
                                                        "iPhone6,2":"iPhone 5s",
                                                        "iPhone7,2":"iPhone 6",
                                                        "iPhone7,1":"iPhone 6 Plus",
                                                        "iPhone8,1":"iPhone 6s",
                                                        "iPhone8,2":"iPhone 6s Plus",
                                                        "iPhone8,4":"iPhone SE",
                                                        "iPad2,1":"iPad 2",
                                                        "iPad2,2":"iPad 2",
                                                        "iPad2,3":"iPad 2",
                                                        "iPad2,4":"iPad 2",
                                                        "iPad3,1":"iPad 3",
                                                        "iPad3,2":"iPad 3",
                                                        "iPad3,3":"iPad 3",
                                                        "iPad3,4":"iPad 4",
                                                        "iPad3,5":"iPad 4",
                                                        "iPad3,6":"iPad 4",
                                                        "iPad4,1":"iPad Air",
                                                        "iPad4,2":"iPad Air",
                                                        "iPad4,3":"iPad Air",
                                                        "iPad5,3":"iPad Air 2",
                                                        "iPad5,4":"iPad Air 2",
                                                        "iPad2,5":"iPad Mini",
                                                        "iPad2,6":"iPad Mini",
                                                        "iPad2,7":"iPad Mini",
                                                        "iPad4,4":"iPad Mini 2",
                                                        "iPad4,5":"iPad Mini 2",
                                                        "iPad4,6":"iPad Mini 2",
                                                        "iPad4,7":"iPad Mini 3",
                                                        "iPad4,8":"iPad Mini 3",
                                                        "iPad4,9":"iPad Mini 3",
                                                        "iPad5,1":"iPad Mini 4",
                                                        "iPad5,2":"iPad Mini 4",
                                                        "iPad6,3":"iPad Pro",
                                                        "iPad6,4":"iPad Pro",
                                                        "iPad6,7":"iPad Pro",
                                                        "iPad6,8":"iPad Pro",
                                                        "AppleTV5,3":"Apple TV",
                                                        "i386":"Simulator",
                                                        "x86_64":"Simulator"
    
            ]
    
            if model!.characters.count > 0 {
                myDeviceName = deviceNamesByCode[model!]!
            }else{
                myDeviceName = UIDevice.currentDevice().model
            }
    
            print("myDeviceName==\(myDeviceName)")
            return myDeviceName
    
        }
    
    0 讨论(0)
  • 2020-11-22 05:24
    //
    //  UIDevice+Hardware.h
    //  gauravds
    //
    
    #import <UIKit/UIKit.h>
    
    @interface UIDevice (Hardware)
    
    - (NSString *)modelIdentifier;
    - (NSString *)modelName;
    
    @end
    

    Why not create a category. Don't use malloc method security leak issue. Use safe functions.

    NSLog(@"%@ %@", [[UIDevice currentDevice] modelName], [[UIDevice currentDevice] modelIdentifier]);
    

    See the implentations

    //
    //  UIDevice+Hardware.m
    //  gauravds
    //
    
    #import "UIDevice+Hardware.h"
    #import <sys/utsname.h>
    
    @implementation UIDevice (Hardware)
    
    - (NSString *)modelIdentifier {
        struct utsname systemInfo;
        uname(&systemInfo);
        return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    }
    
    - (NSString *)modelName {
        return [self modelNameForModelIdentifier:[self modelIdentifier]];
    }
    
    - (NSString *)modelNameForModelIdentifier:(NSString *)modelIdentifier {
        // iPhone http://theiphonewiki.com/wiki/IPhone
    
        if ([modelIdentifier isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
        if ([modelIdentifier isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
        if ([modelIdentifier isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
        if ([modelIdentifier isEqualToString:@"iPhone3,1"])    return @"iPhone 4 (GSM)";
        if ([modelIdentifier isEqualToString:@"iPhone3,2"])    return @"iPhone 4 (GSM Rev A)";
        if ([modelIdentifier isEqualToString:@"iPhone3,3"])    return @"iPhone 4 (CDMA)";
        if ([modelIdentifier isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
        if ([modelIdentifier isEqualToString:@"iPhone5,1"])    return @"iPhone 5 (GSM)";
        if ([modelIdentifier isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (Global)";
        if ([modelIdentifier isEqualToString:@"iPhone5,3"])    return @"iPhone 5c (GSM)";
        if ([modelIdentifier isEqualToString:@"iPhone5,4"])    return @"iPhone 5c (Global)";
        if ([modelIdentifier isEqualToString:@"iPhone6,1"])    return @"iPhone 5s (GSM)";
        if ([modelIdentifier isEqualToString:@"iPhone6,2"])    return @"iPhone 5s (Global)";
        if ([modelIdentifier isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
        if ([modelIdentifier isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
        if ([modelIdentifier isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
        if ([modelIdentifier isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
        if ([modelIdentifier isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
        if ([modelIdentifier isEqualToString:@"iPhone9,1"])    return @"iPhone 7";
        if ([modelIdentifier isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus";
        if ([modelIdentifier isEqualToString:@"iPhone9,3"])    return @"iPhone 7";
        if ([modelIdentifier isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus";
        if ([modelIdentifier isEqualToString:@"iPhone10,1"])   return @"iPhone 8";          // US (Verizon), China, Japan
        if ([modelIdentifier isEqualToString:@"iPhone10,2"])   return @"iPhone 8 Plus";     // US (Verizon), China, Japan
        if ([modelIdentifier isEqualToString:@"iPhone10,3"])   return @"iPhone X";          // US (Verizon), China, Japan
        if ([modelIdentifier isEqualToString:@"iPhone10,4"])   return @"iPhone 8";          // AT&T, Global
        if ([modelIdentifier isEqualToString:@"iPhone10,5"])   return @"iPhone 8 Plus";     // AT&T, Global
        if ([modelIdentifier isEqualToString:@"iPhone10,6"])   return @"iPhone X";          // AT&T, Global
    
        // iPad http://theiphonewiki.com/wiki/IPad
    
        if ([modelIdentifier isEqualToString:@"iPad1,1"])      return @"iPad 1G";
        if ([modelIdentifier isEqualToString:@"iPad2,1"])      return @"iPad 2 (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
        if ([modelIdentifier isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
        if ([modelIdentifier isEqualToString:@"iPad2,4"])      return @"iPad 2 (Rev A)";
        if ([modelIdentifier isEqualToString:@"iPad3,1"])      return @"iPad 3 (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad3,2"])      return @"iPad 3 (GSM)";
        if ([modelIdentifier isEqualToString:@"iPad3,3"])      return @"iPad 3 (Global)";
        if ([modelIdentifier isEqualToString:@"iPad3,4"])      return @"iPad 4 (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad3,5"])      return @"iPad 4 (GSM)";
        if ([modelIdentifier isEqualToString:@"iPad3,6"])      return @"iPad 4 (Global)";
        if ([modelIdentifier isEqualToString:@"iPad6,11"])     return @"iPad (5th gen) (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad6,12"])     return @"iPad (5th gen) (Cellular)";
    
        if ([modelIdentifier isEqualToString:@"iPad4,1"])      return @"iPad Air (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad4,2"])      return @"iPad Air (Cellular)";
        if ([modelIdentifier isEqualToString:@"iPad5,3"])      return @"iPad Air 2 (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad5,4"])      return @"iPad Air 2 (Cellular)";
    
        // iPad Mini http://theiphonewiki.com/wiki/IPad_mini
    
        if ([modelIdentifier isEqualToString:@"iPad2,5"])      return @"iPad mini 1G (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad2,6"])      return @"iPad mini 1G (GSM)";
        if ([modelIdentifier isEqualToString:@"iPad2,7"])      return @"iPad mini 1G (Global)";
        if ([modelIdentifier isEqualToString:@"iPad4,4"])      return @"iPad mini 2G (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad4,5"])      return @"iPad mini 2G (Cellular)";
        if ([modelIdentifier isEqualToString:@"iPad4,6"])      return @"iPad mini 2G (Cellular)"; // TD-LTE model see https://support.apple.com/en-us/HT201471#iPad-mini2
        if ([modelIdentifier isEqualToString:@"iPad4,7"])      return @"iPad mini 3G (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad4,8"])      return @"iPad mini 3G (Cellular)";
        if ([modelIdentifier isEqualToString:@"iPad4,9"])      return @"iPad mini 3G (Cellular)";
        if ([modelIdentifier isEqualToString:@"iPad5,1"])      return @"iPad mini 4G (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad5,2"])      return @"iPad mini 4G (Cellular)";
    
        // iPad Pro https://www.theiphonewiki.com/wiki/IPad_Pro
    
        if ([modelIdentifier isEqualToString:@"iPad6,3"])      return @"iPad Pro (9.7 inch) 1G (Wi-Fi)"; // http://pdadb.net/index.php?m=specs&id=9938&c=apple_ipad_pro_9.7-inch_a1673_wifi_32gb_apple_ipad_6,3
        if ([modelIdentifier isEqualToString:@"iPad6,4"])      return @"iPad Pro (9.7 inch) 1G (Cellular)"; // http://pdadb.net/index.php?m=specs&id=9981&c=apple_ipad_pro_9.7-inch_a1675_td-lte_32gb_apple_ipad_6,4
        if ([modelIdentifier isEqualToString:@"iPad6,7"])      return @"iPad Pro (12.9 inch) 1G (Wi-Fi)"; // http://pdadb.net/index.php?m=specs&id=8960&c=apple_ipad_pro_wifi_a1584_128gb
        if ([modelIdentifier isEqualToString:@"iPad6,8"])      return @"iPad Pro (12.9 inch) 1G (Cellular)"; // http://pdadb.net/index.php?m=specs&id=8965&c=apple_ipad_pro_td-lte_a1652_32gb_apple_ipad_6,8
        if ([modelIdentifier isEqualToString:@"iPad 7,1"])     return @"iPad Pro (12.9 inch) 2G (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad 7,2"])     return @"iPad Pro (12.9 inch) 2G (Cellular)";
        if ([modelIdentifier isEqualToString:@"iPad 7,3"])     return @"iPad Pro (10.5 inch) 1G (Wi-Fi)";
        if ([modelIdentifier isEqualToString:@"iPad 7,4"])     return @"iPad Pro (10.5 inch) 1G (Cellular)";
    
        // iPod http://theiphonewiki.com/wiki/IPod
    
        if ([modelIdentifier isEqualToString:@"iPod1,1"])      return @"iPod touch 1G";
        if ([modelIdentifier isEqualToString:@"iPod2,1"])      return @"iPod touch 2G";
        if ([modelIdentifier isEqualToString:@"iPod3,1"])      return @"iPod touch 3G";
        if ([modelIdentifier isEqualToString:@"iPod4,1"])      return @"iPod touch 4G";
        if ([modelIdentifier isEqualToString:@"iPod5,1"])      return @"iPod touch 5G";
        if ([modelIdentifier isEqualToString:@"iPod7,1"])      return @"iPod touch 6G"; // as 6,1 was never released 7,1 is actually 6th generation
    
        // Apple TV https://www.theiphonewiki.com/wiki/Apple_TV
    
        if ([modelIdentifier isEqualToString:@"AppleTV1,1"])      return @"Apple TV 1G";
        if ([modelIdentifier isEqualToString:@"AppleTV2,1"])      return @"Apple TV 2G";
        if ([modelIdentifier isEqualToString:@"AppleTV3,1"])      return @"Apple TV 3G";
        if ([modelIdentifier isEqualToString:@"AppleTV3,2"])      return @"Apple TV 3G"; // small, incremental update over 3,1
        if ([modelIdentifier isEqualToString:@"AppleTV5,3"])      return @"Apple TV 4G"; // as 4,1 was never released, 5,1 is actually 4th generation
    
        // Simulator
        if ([modelIdentifier hasSuffix:@"86"] || [modelIdentifier isEqual:@"x86_64"])
        {
            BOOL smallerScreen = ([[UIScreen mainScreen] bounds].size.width < 768.0);
            return (smallerScreen ? @"iPhone Simulator" : @"iPad Simulator");
        }
    
        return modelIdentifier;
    }
    
    @end
    
    0 讨论(0)
  • 2020-11-22 05:26

    Below is the code for that (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;
    }
    
    0 讨论(0)
  • 2020-11-22 05:27

    Device name and Machine Names, based on iOS Real Device Hardware

    My solution to this issue is basically looks related to @NicolasMiari answer within this thread. Separate utility class has a predefined set of Device and Machine names and then depending on the real machine name, retrieve the Device Name.

    Note: This answer and it's linked GitHub project has been updated to identify current latest iPhones (iPhone 8, 8+, X) as of October 2017. And this works on iOS11 too. Please visit the GitHub repo and see, and give me feedback if something is wrong.

    /*
     * Retrieves back the device name or if not the machine name.
     */
    + (NSString*)deviceModelName {
        struct utsname systemInfo;
        uname(&systemInfo);
        NSString *machineName = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
        
        //MARK: More official list is at
        //http://theiphonewiki.com/wiki/Models
        //MARK: You may just return machineName. Following is for convenience
        
        NSDictionary *commonNamesDictionary =
        @{
          @"i386":     @"i386 Simulator",
          @"x86_64":   @"x86_64 Simulator",
    
          @"iPhone1,1":    @"iPhone",
          @"iPhone1,2":    @"iPhone 3G",
          @"iPhone2,1":    @"iPhone 3GS",
          @"iPhone3,1":    @"iPhone 4",
          @"iPhone3,2":    @"iPhone 4(Rev A)",
          @"iPhone3,3":    @"iPhone 4(CDMA)",
          @"iPhone4,1":    @"iPhone 4S",
          @"iPhone5,1":    @"iPhone 5(GSM)",
          @"iPhone5,2":    @"iPhone 5(GSM+CDMA)",
          @"iPhone5,3":    @"iPhone 5c(GSM)",
          @"iPhone5,4":    @"iPhone 5c(GSM+CDMA)",
          @"iPhone6,1":    @"iPhone 5s(GSM)",
          @"iPhone6,2":    @"iPhone 5s(GSM+CDMA)",
      
          @"iPhone7,1":    @"iPhone 6+(GSM+CDMA)",
          @"iPhone7,2":    @"iPhone 6(GSM+CDMA)",
      
          @"iPhone8,1":    @"iPhone 6S(GSM+CDMA)",
          @"iPhone8,2":    @"iPhone 6S+(GSM+CDMA)",
          @"iPhone8,4":    @"iPhone SE(GSM+CDMA)",
          @"iPhone9,1":    @"iPhone 7(GSM+CDMA)",
          @"iPhone9,2":    @"iPhone 7+(GSM+CDMA)",
          @"iPhone9,3":    @"iPhone 7(GSM+CDMA)",
          @"iPhone9,4":    @"iPhone 7+(GSM+CDMA)",
      
          @"iPad1,1":  @"iPad",
          @"iPad2,1":  @"iPad 2(WiFi)",
          @"iPad2,2":  @"iPad 2(GSM)",
          @"iPad2,3":  @"iPad 2(CDMA)",
          @"iPad2,4":  @"iPad 2(WiFi Rev A)",
          @"iPad2,5":  @"iPad Mini 1G (WiFi)",
          @"iPad2,6":  @"iPad Mini 1G (GSM)",
          @"iPad2,7":  @"iPad Mini 1G (GSM+CDMA)",
          @"iPad3,1":  @"iPad 3(WiFi)",
          @"iPad3,2":  @"iPad 3(GSM+CDMA)",
          @"iPad3,3":  @"iPad 3(GSM)",
          @"iPad3,4":  @"iPad 4(WiFi)",
          @"iPad3,5":  @"iPad 4(GSM)",
          @"iPad3,6":  @"iPad 4(GSM+CDMA)",
      
          @"iPad4,1":  @"iPad Air(WiFi)",
          @"iPad4,2":  @"iPad Air(GSM)",
          @"iPad4,3":  @"iPad Air(GSM+CDMA)",
      
          @"iPad5,3":  @"iPad Air 2 (WiFi)",
          @"iPad5,4":  @"iPad Air 2 (GSM+CDMA)",
      
          @"iPad4,4":  @"iPad Mini 2G (WiFi)",
          @"iPad4,5":  @"iPad Mini 2G (GSM)",
          @"iPad4,6":  @"iPad Mini 2G (GSM+CDMA)",
      
          @"iPad4,7":  @"iPad Mini 3G (WiFi)",
          @"iPad4,8":  @"iPad Mini 3G (GSM)",
          @"iPad4,9":  @"iPad Mini 3G (GSM+CDMA)",
      
          @"iPod1,1":  @"iPod 1st Gen",
          @"iPod2,1":  @"iPod 2nd Gen",
          @"iPod3,1":  @"iPod 3rd Gen",
          @"iPod4,1":  @"iPod 4th Gen",
          @"iPod5,1":  @"iPod 5th Gen",
          @"iPod7,1":  @"iPod 6th Gen",
          };
        
        NSString *deviceName = commonNamesDictionary[machineName];
        
        if (deviceName == nil) {
            deviceName = machineName;
        }
        
        return deviceName;
    }
    

    I have added this implementation and few other convenient utility methods in a class and put it out there in this GitHub Repository. And also you can find the up to date device information list within this Wiki page.

    Please visit it and get use of it.

    Update:

    You may requires to import sys framework,

    #import <sys/utsname.h>
    
    0 讨论(0)
  • 2020-11-22 05:27
    #import <sys/utsname.h>
    
    #define HARDWARE @{@"i386": @"Simulator",@"x86_64": @"Simulator",@"iPod1,1": @"iPod Touch",@"iPod2,1": @"iPod Touch 2nd Generation",@"iPod3,1": @"iPod Touch 3rd Generation",@"iPod4,1": @"iPod Touch 4th Generation",@"iPhone1,1": @"iPhone",@"iPhone1,2": @"iPhone 3G",@"iPhone2,1": @"iPhone 3GS",@"iPhone3,1": @"iPhone 4",@"iPhone4,1": @"iPhone 4S",@"iPhone5,1": @"iPhone 5",@"iPhone5,2": @"iPhone 5",@"iPhone5,3": @"iPhone 5c",@"iPhone5,4": @"iPhone 5c",@"iPhone6,1": @"iPhone 5s",@"iPhone6,2": @"iPhone 5s",@"iPad1,1": @"iPad",@"iPad2,1": @"iPad 2",@"iPad3,1": @"iPad 3rd Generation ",@"iPad3,4": @"iPad 4th Generation ",@"iPad2,5": @"iPad Mini",@"iPad4,4": @"iPad Mini 2nd Generation - Wifi",@"iPad4,5": @"iPad Mini 2nd Generation - Cellular",@"iPad4,1": @"iPad Air 5th Generation - Wifi",@"iPad4,2": @"iPad Air 5th Generation - Cellular"}
    
    @interface ViewController ()
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        struct utsname systemInfo;
        uname(&systemInfo);
        NSLog(@"hardware: %@",[HARDWARE objectForKey:[NSString stringWithCString: systemInfo.machine encoding:NSUTF8StringEncoding]]);
    }
    
    0 讨论(0)
提交回复
热议问题