Gibt es eine Möglichkeit, das Gerät zu bestimmen, auf dem eine Anwendung läuft? Ich möchte unterscheiden zwischen iPhone
y iPod Touch
wenn möglich.
Antworten
Zu viele Anzeigen?Sie können die UIDevice
Klasse wie diese:
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"])
// it's an iPhone
Dies ist ein Update für UIDeviceHardware.m
von der obige Antwort .
- (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;
}
Sie können diese Klasse gerne verwenden ( gist @ github )
CODE ENTFERNT UND VERLAGERT NACH
アップデイト (01/14/11)
Offensichtlich ist dieser Code inzwischen etwas veraltet, aber er kann sicherlich mit dem Code in diesem Thread aktualisiert werden, der von Brian Robbins
die einen ähnlichen Code mit aktualisierten Modellen enthält. Vielen Dank für die Unterstützung in diesem Thread.
Ich verwende dies in meiner App. Auf dem neuesten Stand von Dezember 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;
}
Letzte Aktualisierung - Dezember 2021: Hinzugefügt iPhone 13 , iPhone 13 mini , iPhone 13 Pro , iPhone 13 Pro Max , iPad (9. Generation), iPad Pro 11" (3. Generation), iPad Pro 12,9" (5. Generation), iPad mini (6. Generation) Apple Watch Serie 7 , iMac 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)
Entfernte Geräte, die iOS 10 nicht unterstützen (wegen der Zeichenbegrenzung)
Schnell
(Getestet auf Swift 5, Swift 4, Swift 3)
Die folgende Funktion gibt eine String mit dem aktuellen Gerätenamen.
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
}
Sie können es mit dem folgenden Code testen:
print("Current device is: ", self.userDeviceName())
Objektiv-C
Ich habe auch neue Geräte zum Objective-C-Code hinzugefügt
Vergessen Sie nicht sys/sysctl.h zu importieren
#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;
}
Sie können es mit dem folgenden Code testen:
NSLog(@"Current device is: %@", [self userDeviceName]);
- See previous answers
- Weitere Antworten anzeigen