374

アプリケーションを実行しているデバイスを特定する方法はありますか。できればiPhoneとを区別したい。iPod Touch

4

31 に答える 31

287

UIDevice次のようにクラスを使用できます。

NSString *deviceType = [UIDevice currentDevice].model;

if([deviceType isEqualToString:@"iPhone"])
    // it's an iPhone
于 2009-01-15T19:54:04.603 に答える
279

これは、上記の回答UIDeviceHardware.mからの更新です。

- (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;
}
于 2010-10-16T20:53:54.257 に答える
122

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.

于 2009-10-13T18:01:40.847 に答える
37

私は自分のアプリでこれを使用しています。2012 年 12 月現在の最新情報です。

- (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;
}  
于 2012-12-03T08:15:15.757 に答える
34

最新アップデート - 2021 年 12 月: iPhone 13iPhone 13 miniiPhone 13 ProiPhone 13 Pro MaxiPad (第 9 世代)、iPad Pro 11" (第 3 世代)、iPad Pro 12,9" (第 5 世代)、iPadを追加mini (第 6 世代) Apple Watch Series 7iMac 24 インチ(M1、2021)、Mac mini (M1、2020)、MacBook Air (M1、2020)、MacBook Pro 13 インチ(M1、2020)、MacBook Pro 14 インチ( M1 Pro/Max、2021)、MacBook Pro 16" (M1 Pro/Max、2021)

iOS 10 をサポートしていないデバイスを削除(文字数制限のため)


迅速

(Swift 5、Swift 4、Swift 3 でテスト済み)

以下の関数は、現在のデバイス名を含む文字列を返します。

func userDeviceName() -> String {
    let platform: String = {
        var size = 0
        sysctlbyname("hw.machine", nil, &size, nil, 0)
        var machine = [CChar](repeating: 0,  count: Int(size))
        sysctlbyname("hw.machine", &machine, &size, nil, 0)
        return String(cString: machine)
    }()
    
    //iPhone
    if platform == "iPhone5,1"        { return "iPhone 5 (GSM)" }
    else if platform == "iPhone5,2"   { return "iPhone 5 (GSM+CDMA)" }
    else if platform == "iPhone5,3"   { return "iPhone 5c (GSM)" }
    else if platform == "iPhone5,4"   { return "iPhone 5c (GSM+CDMA)" }
    else if platform == "iPhone6,1"   { return "iPhone 5s (GSM)" }
    else if platform == "iPhone6,2"   { return "iPhone 5s (GSM+CDMA)" }
    else if platform == "iPhone7,2"   { return "iPhone 6" }
    else if platform == "iPhone7,1"   { return "iPhone 6 Plus" }
    else if platform == "iPhone8,1"   { return "iPhone 6s" }
    else if platform == "iPhone8,2"   { return "iPhone 6s Plus" }
    else if platform == "iPhone8,4"   { return "iPhone SE" }
    else if platform == "iPhone9,1"   { return "iPhone 7 (GSM+CDMA)" }
    else if platform == "iPhone9,3"   { return "iPhone 7 (GSM)" }
    else if platform == "iPhone9,2"   { return "iPhone 7 Plus (GSM+CDMA)" }
    else if platform == "iPhone9,4"   { return "iPhone 7 Plus (GSM)" }
    else if platform == "iPhone10,1"  { return "iPhone 8 (GSM+CDMA)" }
    else if platform == "iPhone10,4"  { return "iPhone 8 (GSM)" }
    else if platform == "iPhone10,2"  { return "iPhone 8 Plus (GSM+CDMA)" }
    else if platform == "iPhone10,5"  { return "iPhone 8 Plus (GSM)" }
    else if platform == "iPhone10,3"  { return "iPhone X (GSM+CDMA)" }
    else if platform == "iPhone10,6"  { return "iPhone X (GSM)" }
    else if platform == "iPhone11,2"  { return "iPhone XS" }
    else if platform == "iPhone11,6"  { return "iPhone XS Max" }
    else if platform == "iPhone11,8"  { return "iPhone XR" }
    else if platform == "iPhone12,1"  { return "iPhone 11" }
    else if platform == "iPhone12,3"  { return "iPhone 11 Pro" }
    else if platform == "iPhone12,5"  { return "iPhone 11 Pro Max" }
    else if platform == "iPhone12,8"  { return "iPhone SE (2nd generation)" }
    else if platform == "iPhone13,1"  { return "iPhone 12 mini" }
    else if platform == "iPhone13,2"  { return "iPhone 12" }
    else if platform == "iPhone13,3"  { return "iPhone 12 Pro" }
    else if platform == "iPhone13,4"  { return "iPhone 12 Pro Max" }
    else if platform == "iPhone14,4"  { return "iPhone 12 mini" }
    else if platform == "iPhone14,5"  { return "iPhone 12" }
    else if platform == "iPhone14,2"  { return "iPhone 12 Pro" }
    else if platform == "iPhone14,3"  { return "iPhone 12 Pro Max" }
        
        //iPod Touch
    else if platform == "iPod7,1"     { return "iPod Touch (6th generation)" }
    else if platform == "iPod9,1"     { return "iPod Touch (7th generation) (2019)" }
        
        //iPad
    else if platform == "iPad3,4"     { return "iPad (4th generation) (Wi-Fi)"}
    else if platform == "iPad3,5"     { return "iPad (4th generation) (GSM)" }
    else if platform == "iPad3,6"     { return "iPad (4th generation) (GSM+CDMA)" }
    else if platform == "iPad6,11"    { return "iPad (5th generation) (Wi-Fi)" }
    else if platform == "iPad6,12"    { return "iPad (5th generation) (Cellular)" }
    else if platform == "iPad7,5"     { return "iPad (6th generation) (2018) (Wi-Fi)" }
    else if platform == "iPad7,6"     { return "iPad (6th generation) (2018) (Cellular)" }
    else if platform == "iPad7,11"    { return "iPad (7th generation) (2019) (Wi-Fi)" }
    else if platform == "iPad7,12"    { return "iPad (7th generation) (2019) (Cellular)" }
    else if platform == "iPad11,6"    { return "iPad (8th generation) (2020) (Wi-Fi)" }
    else if platform == "iPad11,7"    { return "iPad (8th generation) (2020) (Cellular)" }
    else if platform == "iPad12,1"    { return "iPad (9th generation) (2021) (Wi-Fi)" }
    else if platform == "iPad12,2"    { return "iPad (9th generation) (2021) (Cellular)" }
        
        //iPad Air
    else if platform == "iPad4,1"     { return "iPad Air (Wi-Fi)" }
    else if platform == "iPad4,2"     { return "iPad Air (Cellular)" }
    else if platform == "iPad4,3"     { return "iPad Air (China)" }
    else if platform == "iPad5,3"     { return "iPad Air 2 (Wi-Fi)" }
    else if platform == "iPad5,4"     { return "iPad Air 2 (Cellular)" }
    else if platform == "iPad11,3"    { return "iPad Air (3rd generation) (2019) (Wi-Fi)" }
    else if platform == "iPad11,4"    { return "iPad Air (3rd generation) (2019) (Cellular)" }
    else if platform == "iPad13,1"    { return "iPad Air (4th generation) (2020) (Wi-Fi)" }
    else if platform == "iPad13,2"    { return "iPad Air (4th generation) (2020) (Cellular)" }
        
        //iPad Pro
    else if platform == "iPad6,3"     { return "iPad Pro 9.7\" (Wi-Fi)" }
    else if platform == "iPad6,4"     { return "iPad Pro 9.7\" (Cellular)" }
    else if platform == "iPad6,7"     { return "iPad Pro 12.9\" (Wi-Fi)" }
    else if platform == "iPad6,8"     { return "iPad Pro 12.9\" (Cellular)" }
    else if platform == "iPad7,1"     { return "iPad Pro 12.9\" (2nd generation) (Wi-Fi)" }
    else if platform == "iPad7,2"     { return "iPad Pro 12.9\" (2nd generation) (Cellular)" }
    else if platform == "iPad7,3"     { return "iPad Pro 10.5\" (Wi-Fi)" }
    else if platform == "iPad7,4"     { return "iPad Pro 10.5\" (Cellular)" }
    else if platform == "iPad8,1"     { return "iPad Pro 11\" (2018) (Wi-Fi)" }
    else if platform == "iPad8,2"     { return "iPad Pro 11\" (2018) (Wi-Fi, 1TB)" }
    else if platform == "iPad8,3"     { return "iPad Pro 11\" (2018) (Cellular)" }
    else if platform == "iPad8,4"     { return "iPad Pro 11\" (2018) (Cellular 1TB)" }
    else if platform == "iPad8,5"     { return "iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi)" }
    else if platform == "iPad8,6"     { return "iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi, 1TB)" }
    else if platform == "iPad8,7"     { return "iPad Pro 12.9\" (3rd generation) (2018) (Cellular)" }
    else if platform == "iPad8,8"     { return "iPad Pro 12.9\" (3rd generation) (2018) (Cellular, 1TB)" }
    else if platform == "iPad8,9"     { return "iPad Pro 11\" (2nd generation) (2020) (Wi-Fi)" }
    else if platform == "iPad8,10"    { return "iPad Pro 11\" (2nd generation) (2020) (Cellular)" }
    else if platform == "iPad8,11"    { return "iPad Pro 12.9\" (4th generation) (2020) (Wi-Fi)" }
    else if platform == "iPad8,12"    { return "iPad Pro 12.9\" (4th generation) (2020) (Cellular)" }
    else if platform == "iPad13,4"    { return "iPad Pro 11\" (3nd generation) (2021) (Wi-Fi)" }
    else if platform == "iPad13,5"    { return "iPad Pro 11\" (3nd generation) (2021) (Cellular US)" }
    else if platform == "iPad13,6"    { return "iPad Pro 11\" (3nd generation) (2021) (Cellular Global)" }
    else if platform == "iPad13,7"    { return "iPad Pro 11\" (3nd generation) (2021) (Cellular China)" }
    else if platform == "iPad13,8"    { return "iPad Pro 12.9\" (5th generation) (2021) (Wi-Fi)" }
    else if platform == "iPad13,9"    { return "iPad Pro 12.9\" (5th generation) (2021) (Cellular US)" }
    else if platform == "iPad13,10"   { return "iPad Pro 12.9\" (5th generation) (2021) (Cellular Global)" }
    else if platform == "iPad13,11"   { return "iPad Pro 12.9\" (5th generation) (2021) (Cellular China)" }
        
        //iPad Mini
    else if platform == "iPad4,4"     { return "iPad mini 2 (Wi-Fi)" }
    else if platform == "iPad4,5"     { return "iPad mini 2 (Cellular)" }
    else if platform == "iPad4,6"     { return "iPad mini 2 (China)" }
    else if platform == "iPad4,7"     { return "iPad mini 3 (Wi-Fi)" }
    else if platform == "iPad4,8"     { return "iPad mini 3 (Cellular)" }
    else if platform == "iPad4,9"     { return "iPad mini 3 (China)" }
    else if platform == "iPad5,1"     { return "iPad mini 4 (Wi-Fi)" }
    else if platform == "iPad5,2"     { return "iPad mini 4 (Cellular)" }
    else if platform == "iPad11,1"    { return "iPad mini (5th generation) (2019) (Wi-Fi)" }
    else if platform == "iPad11,2"    { return "iPad mini (5th generation) (2019) (Cellular)" }
    else if platform == "iPad14,1"    { return "iPad mini (6th generation) (2021) (Wi-Fi)" }
    else if platform == "iPad14,2"    { return "iPad mini (6th generation) (2021) (Cellular)" }
        
        //Apple TV
    else if platform == "AppleTV2,1"  { return "Apple TV 2G" }
    else if platform == "AppleTV3,1"  { return "Apple TV 3" }
    else if platform == "AppleTV3,2"  { return "Apple TV 3 (2013)" }
    else if platform == "AppleTV5,3"  { return "Apple TV 4" }
    else if platform == "AppleTV6,2"  { return "Apple TV 4K" }
    else if platform == "AppleTV11,1" { return "Apple TV 4K (2nd generation)" }
        
        //Apple Watch
    else if platform == "Watch1,1"    { return "Apple Watch (1st generation) (38mm)" }
    else if platform == "Watch1,2"    { return "Apple Watch (1st generation) (42mm)" }
    else if platform == "Watch2,6"    { return "Apple Watch Series 1 (38mm)" }
    else if platform == "Watch2,7"    { return "Apple Watch Series 1 (42mm)" }
    else if platform == "Watch2,3"    { return "Apple Watch Series 2 (38mm)" }
    else if platform == "Watch2,4"    { return "Apple Watch Series 2 (42mm)" }
    else if platform == "Watch3,1"    { return "Apple Watch Series 3 (38mm Cellular)" }
    else if platform == "Watch3,2"    { return "Apple Watch Series 3 (42mm Cellular)" }
    else if platform == "Watch3,3"    { return "Apple Watch Series 3 (38mm)" }
    else if platform == "Watch3,4"    { return "Apple Watch Series 3 (42mm)" }
    else if platform == "Watch4,1"    { return "Apple Watch Series 4 (40mm)" }
    else if platform == "Watch4,2"    { return "Apple Watch Series 4 (44mm)" }
    else if platform == "Watch4,3"    { return "Apple Watch Series 4 (40mm Cellular)" }
    else if platform == "Watch4,4"    { return "Apple Watch Series 4 (44mm Cellular)" }
    else if platform == "Watch5,1"    { return "Apple Watch Series 5 (40mm)" }
    else if platform == "Watch5,2"    { return "Apple Watch Series 5 (44mm)" }
    else if platform == "Watch5,3"    { return "Apple Watch Series 5 (40mm Cellular)" }
    else if platform == "Watch5,4"    { return "Apple Watch Series 5 (44mm Cellular)" }
    else if platform == "Watch6,1"    { return "Apple Watch Series 6 (40mm)" }
    else if platform == "Watch6,2"    { return "Apple Watch Series 6 (44mm)" }
    else if platform == "Watch6,3"    { return "Apple Watch Series 6 (40mm Cellular)" }
    else if platform == "Watch6,4"    { return "Apple Watch Series 6 (44mm Cellular)" }
    else if platform == "Watch5,9"    { return "Apple Watch SE (40mm)" }
    else if platform == "Watch5,10"   { return "Apple Watch SE (44mm)" }
    else if platform == "Watch5,11"   { return "Apple Watch SE (40mm Cellular)" }
    else if platform == "Watch5,12"   { return "Apple Watch SE (44mm Cellular)" }
    else if platform == "Watch6,6"    { return "Apple Watch Series 7 (41mm)" }
    else if platform == "Watch6,7"    { return "Apple Watch Series 7 (45mm)" }
    else if platform == "Watch6,8"    { return "Apple Watch Series 7 (41mm Cellular)" }
    else if platform == "Watch6,9"    { return "Apple Watch Series 7 (45mm Cellular)" }
    
        //iMac
    else if platform == "iMac21,1"        { return "iMac 24\" (M1, 2021)" }
    else if platform == "iMac21,2"        { return "iMac 24\" (M1, 2021)" }
        //Mac mini
    else if platform == "Macmini9,1"      { return "Mac mini (M1, 2020)" }
        //MacBookAir
    else if platform == "MacBookAir10,1"  { return "MacBook Air (M1, Late 2020)" }
        //MacBook Pro
    else if platform == "MacBookPro17,1"  { return "MacBook Pro 13\"  (M1, 2020)" }
    else if platform == "MacBookPro18,3"  { return "MacBook Pro 14\" (M1 Pro, 2021)" }
    else if platform == "MacBookPro18,4"  { return "MacBook Pro 14\" (M1 Max, 2021)" }
    else if platform == "MacBookPro18,1"  { return "MacBook Pro 16\" (M1 Pro, 2021)" }
    else if platform == "MacBookPro18,2"  { return "MacBook Pro 16\" (M1 Max, 2021)" }
        
        //Simulator
    else if platform == "i386"        { return "Simulator" }
    else if platform == "x86_64"      { return "Simulator"}

    return platform
}

次のコードを使用してテストできます。

print("Current device is: ", self.userDeviceName())

Objective-C

また、Objective-C コードに新しいデバイスを追加しました

sys/sysctl.h をインポートすることを忘れないでください

     #import <sys/sysctl.h>  


- (NSString *) userDeviceName {
    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);

    //iPhone
    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 (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone9,3"])    return @"iPhone 7 (GSM)";
    if ([platform isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus (GSM)";
    if ([platform isEqualToString:@"iPhone10,1"])   return @"iPhone 8 (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone10,4"])   return @"iPhone 8 (GSM)";
    if ([platform isEqualToString:@"iPhone10,2"])   return @"iPhone 8 Plus (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone10,5"])   return @"iPhone 8 Plus (GSM)";
    if ([platform isEqualToString:@"iPhone10,3"])   return @"iPhone X (GSM+CDMA)";
    if ([platform isEqualToString:@"iPhone10,6"])   return @"iPhone X (GSM)";
    if ([platform isEqualToString:@"iPhone11,2"])   return @"iPhone XS";
    if ([platform isEqualToString:@"iPhone11,6"])   return @"iPhone XS Max";
    if ([platform isEqualToString:@"iPhone11,8"])   return @"iPhone XR";
    if ([platform isEqualToString:@"iPhone12,1"])   return @"iPhone 11";
    if ([platform isEqualToString:@"iPhone12,3"])   return @"iPhone 11 Pro";
    if ([platform isEqualToString:@"iPhone12,5"])   return @"iPhone 11 Pro Max";
    if ([platform isEqualToString:@"iPhone12,8"])   return @"iPhone SE (2nd generation)";
    if ([platform isEqualToString:@"iPhone13,1"])   return @"iPhone 12 mini";
    if ([platform isEqualToString:@"iPhone13,2"])   return @"iPhone 12";
    if ([platform isEqualToString:@"iPhone13,3"])   return @"iPhone 12 Pro";
    if ([platform isEqualToString:@"iPhone13,4"])   return @"iPhone 12 Pro Max";
    if ([platform isEqualToString:@"iPhone14,4"])   return @"iPhone 13 mini";
    if ([platform isEqualToString:@"iPhone14,5"])   return @"iPhone 13";
    if ([platform isEqualToString:@"iPhone14,2"])   return @"iPhone 13 Pro";
    if ([platform isEqualToString:@"iPhone14,3"])   return @"iPhone 13 Pro Max";

    //iPod Touch
    if ([platform isEqualToString:@"iPod7,1"])      return @"iPod Touch (6th generation)";
    if ([platform isEqualToString:@"iPod9,1"])      return @"iPod Touch (7th generation) (2019)";

    //iPad
    if ([platform isEqualToString:@"iPad3,4"])      return @"iPad (4th generation) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad3,5"])      return @"iPad (4th generation) (GSM)";
    if ([platform isEqualToString:@"iPad3,6"])      return @"iPad (4th generation) (GSM+CDMA)";
    if ([platform isEqualToString:@"iPad6,11"])     return @"iPad (5th generation) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad6,12"])     return @"iPad (5th generation) (Cellular)";
    if ([platform isEqualToString:@"iPad7,5"])      return @"iPad (6th generation) (2018) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad7,6"])      return @"iPad (6th generation) (2018) (Cellular)";
    if ([platform isEqualToString:@"iPad7,11"])     return @"iPad (7th generation) (2019) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad7,12"])     return @"iPad (7th generation) (2019) (Cellular)";
    if ([platform isEqualToString:@"iPad11,6"])     return @"iPad (8th generation) (2020) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad11,7"])     return @"iPad (8th generation) (2020) (Cellular)";
    if ([platform isEqualToString:@"iPad12,1"])     return @"iPad (9th generation) (2021) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad12,2"])     return @"iPad (9th generation) (2021) (Cellular)";

    //iPad Air
    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:@"iPad5,3"])      return @"iPad Air 2 (Wi-Fi)";
    if ([platform isEqualToString:@"iPad5,4"])      return @"iPad Air 2 (Cellular)";
    if ([platform isEqualToString:@"iPad11,3"])     return @"iPad Air (3rd generation) (2019) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad11,4"])     return @"iPad Air (3rd generation) (2019) (Cellular)";
    if ([platform isEqualToString:@"iPad13,1"])     return @"iPad Air (4th generation) (2020) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad13,2"])     return @"iPad Air (4th generation) (2020) (Cellular)";

    //iPad Pro
    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:@"iPad7,1"])      return @"iPad Pro 12.9\" (2nd generation) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad7,2"])      return @"iPad Pro 12.9\" (2nd generation) (Cellular)";
    if ([platform isEqualToString:@"iPad7,3"])      return @"iPad Pro 10.5\" (Wi-Fi)";
    if ([platform isEqualToString:@"iPad7,4"])      return @"iPad Pro 10.5\" (Cellular)";
    if ([platform isEqualToString:@"iPad8,1"])      return @"iPad Pro 11\" (2018) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad8,2"])      return @"iPad Pro 11\" (2018) (Wi-Fi, 1TB)";
    if ([platform isEqualToString:@"iPad8,3"])      return @"iPad Pro 11\" (2018) (Cellular)";
    if ([platform isEqualToString:@"iPad8,4"])      return @"iPad Pro 11\" (2018) (Cellular, 1Tb)";
    if ([platform isEqualToString:@"iPad8,5"])      return @"iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad8,6"])      return @"iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi, 1TB)";
    if ([platform isEqualToString:@"iPad8,7"])      return @"iPad Pro 12.9\" (3rd generation) (2018) (Cellular)";
    if ([platform isEqualToString:@"iPad8,8"])      return @"iPad Pro 12.9\" (3rd generation) (2018) (Cellular, 1TB)";
    if ([platform isEqualToString:@"iPad8,9"])      return @"iPad Pro 11\" (2nd generation) (2020) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad8,10"])     return @"iPad Pro 11\" (2nd generation) (2020) (Cellular)";
    if ([platform isEqualToString:@"iPad8,11"])     return @"iPad Pro 12.9\" (4th generation) (2020) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad8,12"])     return @"iPad Pro 12.9\" (4th generation) (2020) (Cellular)";
    if ([platform isEqualToString:@"iPad13,4"])     return @"iPad Pro 11\" (3nd generation) (2021) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad13,5"])     return @"iPad Pro 11\" (3nd generation) (2021) (Cellular US)";
    if ([platform isEqualToString:@"iPad13,6"])     return @"iPad Pro 11\" (3nd generation) (2021) (Cellular Global)";
    if ([platform isEqualToString:@"iPad13,7"])     return @"iPad Pro 11\" (3nd generation) (2021) (Cellular China)";
    if ([platform isEqualToString:@"iPad13,8"])     return @"iPad Pro 12.9\" (5th generation) (2021) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad13,9"])     return @"iPad Pro 12.9\" (5th generation) (2021) (Cellular US)";
    if ([platform isEqualToString:@"iPad13,10"])    return @"iPad Pro 12.9\" (5th generation) (2021) (Cellular Global)";
    if ([platform isEqualToString:@"iPad13,11"])    return @"iPad Pro 12.9\" (5th generation) (2021) (Cellular China)";

    //iPad mini
    if ([platform isEqualToString:@"iPad4,4"])      return @"iPad mini 2 (Wi-Fi)";
    if ([platform isEqualToString:@"iPad4,5"])      return @"iPad mini 2 (Cellular)";
    if ([platform isEqualToString:@"iPad4,6"])      return @"iPad mini 2 (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:@"iPad11,1"])     return @"iPad mini (5th generation) (2019) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad11,2"])     return @"iPad mini (5th generation) (2019) (Cellular)";
    if ([platform isEqualToString:@"iPad14,1"])     return @"iPad mini (6th generation) (2021) (Wi-Fi)";
    if ([platform isEqualToString:@"iPad14,2"])     return @"iPad mini (6th generation) (2021) (Cellular)";
    
    //Apple TV
    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:@"AppleTV6,2"])   return @"Apple TV 4K";
    if ([platform isEqualToString:@"AppleTV11,1"])  return @"Apple TV 4K (2nd generation)";

    //Apple Watch
    if ([platform isEqualToString:@"Watch1,1"])     return @"Apple Watch (1st generation) (38mm)";
    if ([platform isEqualToString:@"Watch1,2"])     return @"Apple Watch (1st generation) (42mm)";
    if ([platform isEqualToString:@"Watch2,6"])     return @"Apple Watch Series 1 (38mm)";
    if ([platform isEqualToString:@"Watch2,7"])     return @"Apple Watch Series 1 (42mm)";
    if ([platform isEqualToString:@"Watch2,3"])     return @"Apple Watch Series 2 (38mm)";
    if ([platform isEqualToString:@"Watch2,4"])     return @"Apple Watch Series 2 (42mm)";
    if ([platform isEqualToString:@"Watch3,1"])     return @"Apple Watch Series 3 (38mm Cellular)";
    if ([platform isEqualToString:@"Watch3,2"])     return @"Apple Watch Series 3 (42mm Cellular)";
    if ([platform isEqualToString:@"Watch3,3"])     return @"Apple Watch Series 3 (38mm)";
    if ([platform isEqualToString:@"Watch3,4"])     return @"Apple Watch Series 3 (42mm)";
    if ([platform isEqualToString:@"Watch4,1"])     return @"Apple Watch Series 4 (40mm)";
    if ([platform isEqualToString:@"Watch4,2"])     return @"Apple Watch Series 4 (44mm)";
    if ([platform isEqualToString:@"Watch4,3"])     return @"Apple Watch Series 4 (40mm Cellular)";
    if ([platform isEqualToString:@"Watch4,4"])     return @"Apple Watch Series 4 (44mm Cellular)";
    if ([platform isEqualToString:@"Watch5,1"])     return @"Apple Watch Series 5 (40mm)";
    if ([platform isEqualToString:@"Watch5,2"])     return @"Apple Watch Series 5 (44mm)";
    if ([platform isEqualToString:@"Watch5,3"])     return @"Apple Watch Series 5 (40mm Cellular)";
    if ([platform isEqualToString:@"Watch5,4"])     return @"Apple Watch Series 5 (44mm Cellular)";
    if ([platform isEqualToString:@"Watch6,1"])     return @"Apple Watch Series 6 (40mm)";
    if ([platform isEqualToString:@"Watch6,2"])     return @"Apple Watch Series 6 (44mm)";
    if ([platform isEqualToString:@"Watch6,3"])     return @"Apple Watch Series 6 (40mm Cellular)";
    if ([platform isEqualToString:@"Watch6,4"])     return @"Apple Watch Series 6 (44mm Cellular)";
    if ([platform isEqualToString:@"Watch5,9"])     return @"Apple Watch SE (40mm)";
    if ([platform isEqualToString:@"Watch5,10"])    return @"Apple Watch SE (44mm)";
    if ([platform isEqualToString:@"Watch5,11"])    return @"Apple Watch SE (40mm Cellular)";
    if ([platform isEqualToString:@"Watch5,12"])    return @"Apple Watch SE (44mm Cellular)";
    if ([platform isEqualToString:@"Watch6,6"])     return @"Apple Watch Series 7 (41mm)";
    if ([platform isEqualToString:@"Watch6,7"])     return @"Apple Watch Series 7 (45mm)";
    if ([platform isEqualToString:@"Watch6,8"])     return @"Apple Watch Series 7 (41mm Cellular)";
    if ([platform isEqualToString:@"Watch6,9"])     return @"Apple Watch Series 7 (45mm Cellular)";

    //iMac
    if ([platform isEqualToString:@"iMac21,1"])        return @"iMac 24\" (M1, 2021)";
    if ([platform isEqualToString:@"iMac21,2"])        return @"iMac 24\" (M1, 2021)";
    //Mac mini
    if ([platform isEqualToString:@"Macmini9,1"])      return @"Mac mini (M1, 2020)";
    //MacBookAir
    if ([platform isEqualToString:@"MacBookAir10,1"])  return @"MacBook Air (M1, Late 2020)";
    //MacBook Pro
    if ([platform isEqualToString:@"MacBookPro17,1"])  return @"MacBook Pro 13\"  (M1, 2020)";
    if ([platform isEqualToString:@"MacBookPro18,3"])  return @"MacBook Pro 14\" (M1 Pro, 2021)";
    if ([platform isEqualToString:@"MacBookPro18,4"])  return @"MacBook Pro 14\" (M1 Max, 2021)";
    if ([platform isEqualToString:@"MacBookPro18,1"])  return @"MacBook Pro 16\" (M1 Pro, 2021)";
    if ([platform isEqualToString:@"MacBookPro18,2"])  return @"MacBook Pro 16\" (M1 Max, 2021)";

    //Simulator
    if ([platform isEqualToString:@"i386"])         return @"Simulator";
    if ([platform isEqualToString:@"x86_64"])       return @"Simulator";

    return platform;
}

次のコードを使用してテストできます。

NSLog(@"Current device is: %@", [self userDeviceName]);
于 2016-04-19T11:55:02.860 に答える
27
if([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad) {
    //Device is ipad 
}else{
    //Device is iphone
}
于 2012-06-19T10:08:01.163 に答える
14

iPad Air 2およびのプラットフォーム文字列を更新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;
}
于 2014-12-24T00:39:37.290 に答える
12

より使いやすい

#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

あなたはでプロパティを読むことができます

NSLog(@"platform %@, retita %@, multitasking %@", [[UIDevice currentDevice] platform], [[UIDevice currentDevice] hasRetinaDisplay] ? @"YES" : @"NO" , [[UIDevice currentDevice] hasMultitasking] ? @"YES" : @"NO");
于 2010-10-18T10:39:47.467 に答える
10

新しいモデルのマイナーアップデートは次のとおりです。

- (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;
}
于 2010-07-23T18:55:53.663 に答える
10

回答がすでにチェックされていることは知っていますが、今後の参考のために、いつでもデバイスの画面サイズを使用して、どのデバイスがどのようなデバイスであるかを把握できます。

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.");
}
于 2015-06-05T11:34:13.730 に答える
8

iPhone 4S デバイス コードをこのスレッドに追加するだけです...

iPhone 4S は文字列 @"iPhone4,1" を返します。

于 2011-11-06T00:35:31.773 に答える
6

このコードはどうですか。新しいバージョンがリリースされた場合、最後に知っているデバイスで識別します

- (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;
}
于 2011-12-12T17:57:52.463 に答える
6

Arash のコードに追加すると、使用しているモデルのアプリは気にしません。デバイスの種類を知りたいだけなので、次のようにテストできます。

    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");

                }
}
于 2013-01-12T17:57:15.613 に答える
5

上記の非常に良い答えに基づいて、ここに私が思いついたものがあります。これは@Rodrigoの回答と非常に似ていますが、その回答に対するコメントから@Oliverの懸念に対処しています。これにより、出力文字列にモデル文字列を含めるオプションも提供されます。

+ (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];
}
于 2012-01-13T03:57:23.860 に答える
5

SDVersionと呼ばれるかなり成熟したライブラリ(私による)があります。実行中のデバイスのモデル、画面サイズ、およびその他の多くのパラメーターを確認できます。OSXにも対応しています。

例:

      // 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");
于 2015-09-06T22:07:31.590 に答える
4
#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;
}
于 2015-04-25T12:13:17.920 に答える
4
NSString *deviceType = [UIDevice currentDevice].model;
于 2013-05-22T06:59:46.993 に答える
3

以下のコード スニペットが役立ちます。

 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
   // iPhone device
 }
 else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
   // iPad device
 }
 else {
  // Other device i.e. iPod
 }
于 2014-03-10T13:58:48.463 に答える
3

私はそれをもう少し進めて、大きな「isEqualToString」ブロックを、デバイス タイプ、世代、およびカンマの後の他の修飾子 (サブ世代と呼んでいます) のビット マスクの分類に変換しました。これは、多くの反復的な文字列操作を回避するシングルトン コール SGPlatform を使用してクラスにラップされます。コードはhttps://github.com/danloughney/spookyGroupで入手できます

このクラスでは、次のようなことができます。

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

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

デバイスの分類は platformBits メソッドにあります。その方法は、このスレッドの読者にはよく知られているはずです。主に全体的なパフォーマンスに関心があるため、デバイスをタイプと世代で分類しましたが、ソースを微調整して、関心のある分類、網膜スクリーン、ネットワーク機能などを提供できます.

于 2013-09-18T12:03:58.140 に答える
2
- (BOOL)deviceiPhoneOriPod
  {
    NSString *deviceType = [UIDevice currentDevice].model;
    if([deviceType rangeOfString:@"iPhone"].location!=NSNotFound)
      return YES;
    else
      return NO;
  }
于 2012-12-21T10:57:05.213 に答える
1

可能な値

[[UIDevice currentDevice] model];

、、、、iPod touch_ iPhone_ iPhone Simulator_ iPad_iPad Simulator

、などのようにどのハードウェアiOSが台無しになっているのかを知りたい場合は、以下がそのコードですiPhone3iPhone4iPhone5


注:以下のコードにはすべてのデバイスの文字列が含まれているとは限りません。他の人がGitHubで同じコードを維持しているので、そこから最新のコードを取得してください。

Objective-C : GitHub/DeviceUtil

スウィフト: 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;
}
于 2015-04-13T06:26:23.120 に答える
1

Dutchie432Brian Robbins優れたソリューションを提供してきました。しかし、 Verizon iPhone 4という 1 つのモデルがまだありません。これが行方不明の行です。

if ([platform isEqualToString:@"iPhone3,2"])    return @"iPhone 4"; //Verizon
于 2011-03-20T08:16:10.640 に答える
0

iPhone 4S を識別するには、以下を確認してください。

var isIphone4S: Bool {

    let width = UIScreen.main.bounds.size.width
    let height = UIScreen.main.bounds.size.height
    let proportions = width > height ? width / height : height / width

    return proportions == 1.5 && UIDevice.current.model == "iPhone"
}
于 2017-01-08T23:22:47.707 に答える
0
NSString *deviceType = [[UIDevice currentDevice] systemName];

上記で提案されたものは、iOS 7 以降で動作することを保証できます。iOS 6 でも動くと思います。しかし、それについてはわかりません。

于 2014-11-14T06:17:04.623 に答える
0

GitHub でGBDeviceInfoを確認できます。また、CocoaPods からも入手できます。最新のすべてのデバイスをサポートして、さまざまなプロパティを検出するためのシンプルな API を提供します。

  • デバイスファミリー

[GBDeviceInfo deviceDetails].family == GBDeviceFamilyiPhone;

  • デバイスモデル

[GBDeviceInfo deviceDetails].model == GBDeviceModeliPhone6.

詳細については、Readmeを参照してください。

于 2015-01-18T20:00:43.217 に答える
-1

プラットフォーム文字列を更新します。

// Created from this thread: https://gist.github.com/Jaybles/1323251

// Apple TV
if ([platform isEqualToString:@"AppleTV2,1"])   return @"Apple TV 2G";
if ([platform isEqualToString:@"AppleTV3,1"])   return @"Apple TV 3G";
if ([platform isEqualToString:@"AppleTV3,2"])   return @"Apple TV 3G";
if ([platform isEqualToString:@"AppleTV5,3"])   return @"Apple TV 4G";

// Apple Watch
if ([platform isEqualToString:@"Watch1,1"])     return @"Apple Watch";
if ([platform isEqualToString:@"Watch1,2"])     return @"Apple Watch";

// iPhone
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 (GSM)";
if ([platform isEqualToString:@"iPhone3,2"])    return @"iPhone 4 (GSM/2012)";
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 (GSM)";
if ([platform isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (Global)";
if ([platform isEqualToString:@"iPhone5,3"])    return @"iPhone 5c (GSM)";
if ([platform isEqualToString:@"iPhone5,4"])    return @"iPhone 5c (Global)";
if ([platform isEqualToString:@"iPhone6,1"])    return @"iPhone 5s (GSM)";
if ([platform isEqualToString:@"iPhone6,2"])    return @"iPhone 5s (Global)";
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 (Global)";
if ([platform isEqualToString:@"iPhone9,3"])    return @"iPhone 7 (GSM)";
if ([platform isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus (Global)";
if ([platform isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus (GSM)";

// iPad
if ([platform isEqualToString:@"iPad1,1"])      return @"iPad 1";
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 (Mid 2012)";
if ([platform isEqualToString:@"iPad3,1"])      return @"iPad 3 (WiFi)";
if ([platform isEqualToString:@"iPad3,2"])      return @"iPad 3 (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 (Global)";

// iPad Air
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 (China)";
if ([platform isEqualToString:@"iPad5,3"])      return @"iPad Air 2 (WiFi)";
if ([platform isEqualToString:@"iPad5,4"])      return @"iPad Air 2 (Cellular)";

// iPad Mini
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 (Global)";
if ([platform isEqualToString:@"iPad4,4"])      return @"iPad Mini 2 (WiFi)";
if ([platform isEqualToString:@"iPad4,5"])      return @"iPad Mini 2 (Cellular)";
if ([platform isEqualToString:@"iPad4,6"])      return @"iPad Mini 2 (China)";
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,1"])      return @"iPad Mini 4 (WiFi)";
if ([platform isEqualToString:@"iPad5,2"])      return @"iPad Mini 4 (Cellular)";

// iPad Pro
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)";

// iPod
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";

// Simulator
if ([platform isEqualToString:@"i386"])         return @"Simulator";
if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
于 2017-02-02T20:00:57.917 に答える