IOS cihazı (iPhone, iPod Touch) ilə iOS

Ehtiyacınızı aradan qaldırın, qurmaq istəsəniz. iPhoneiPod Touch -nu istəmirəm, əgər bu mümkündürsə.

361
15 янв. müəllif Rob 15 янв . 2009-01-15 22:36 '09 v 22:36 2009-01-15 22:36
ответ 31 cavab
  • 1
  • 2

UIDevice использовать класс UIDevice :

 NSString *deviceType = [UIDevice currentDevice].model; if([deviceType isEqualToString:@"iPhone"]) // it an iPhone 
284
15 янв. ответ на Adam Rosenfield 15 янв. 2009-01-15 22:54 '09 v 22:54 2009-01-15 22:54

Bu yeniləmə üçün UIDeviceHardware.m cavab ala bilərsiniz.

border=0
 - (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; } 
276
16 окт. Brian Robbins- dan cavab 16 oktyabr. 2010-10-16 23:53 '10 в 23:53 2010-10-16 23:53

Pozalanmayacaq, bu halda istifadə edin ( gist @ github )

КОД, УДАЛЕННЫЙ И ПЕРЕМЕЩЕННЫЙ

https://gist.github.com/1323251

ОБНОВЛЕНИЕ (01/14/11)

Bəli, Brian Robbins , köçürdüyü kodunu yeniləyir, yeniləyir, yenə yenilənir, yenə yenilənmiş modelləri yeniləyir. Bu mövzuda mənə dəstək verin.

122
13 окт. ответ от Dutchie432 13 окт . 2009-10-13 21:01 '09 в 21:01 2009-10-13 21:01

Я использую это в своем приложении. Dekabr 2012-ci ildə yenilənib.

 - (NSString *) platformString { // Gets a string with the device model size_t size; sysctlbyname("hw.machine", NULL,  NULL, 0); char *machine = malloc(size); sysctlbyname("hw.machine", machine,  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; } 
37
03 дек. otvet dan Tomasz 03 dek. 2012-12-03 11:15 '12 saat 11:15 2012-12-03 11:15
 if([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad) { //Device is ipad }else{ //Device is iphone } 
27
19 июня '12 в 13:08 2012-06-19 13:08 ответ дан Gurpreet Singh 19 сентября '12 в 13:08 2012-06-19 13:08

Son yeniləmə - Sentyabr 2017 Əlavə IPhone X , iPhone 8 , iPhone 8 Plus , Apple Watch Series 3 , Apple TV 4K

Предыдущее обновление - İyun 2017: Добавлено iPad Pro 10,5 " iPad 12,9" 2-ci Gen


Cəld

(Протестировано на Swift 4, Swift 3)

Функция ниже возвращает строку с текущим именем устройства.

 func userDeviceName() -> String { let platform: String = { var size = 0 sysctlbyname("hw.machine", nil,  nil, 0) var machine = [CChar](repeating: 0, count: Int(size)) sysctlbyname("hw.machine",   nil, 0) return String(cString: machine) }() //iPhone if platform == "iPhone1,1" { return "iPhone (1st generation)" } else if platform == "iPhone1,2" { return "iPhone 3G" } else if platform == "iPhone2,1" { return "iPhone 3GS" } else if platform == "iPhone3,1" { return "iPhone 4 (GSM)" } else if platform == "iPhone3,2" { return "iPhone 4 (GSM, 2nd revision)" } else if platform == "iPhone3,3" { return "iPhone 4 (CDMA)" } else if platform == "iPhone4,1" { return "iPhone 4S" } else 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)" } //iPod Touch else if platform == "iPod1,1" { return "iPod Touch 1G" } else if platform == "iPod2,1" { return "iPod Touch 2G" } else if platform == "iPod3,1" { return "iPod Touch 3G" } else if platform == "iPod4,1" { return "iPod Touch 4G" } else if platform == "iPod5,1" { return "iPod Touch 5G" } else if platform == "iPod7,1" { return "iPod Touch 6G" } //iPad else if platform == "iPad1,1" { return "iPad (1st generation)" } else if platform == "iPad2,1" { return "iPad 2 (Wi-Fi)" } else if platform == "iPad2,2" { return "iPad 2 (GSM)" } else if platform == "iPad2,3" { return "iPad 2 (CDMA)" } else if platform == "iPad2,4" { return "iPad 2 (Wi-Fi, Mid 2012)" } else if platform == "iPad3,1" { return "iPad (3rd generation) (Wi-Fi)" } else if platform == "iPad3,2" { return "iPad (3rd generation) (GSM+CDMA)" } else if platform == "iPad3,3" { return "iPad (3rd generation) (GSM)" } 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)" } //iPad Mini else if platform == "iPad2,5" { return "iPad Mini (Wi-Fi)" } else if platform == "iPad2,6" { return "iPad Mini (GSM)" } else if platform == "iPad2,7" { return "iPad Mini (GSM+CDMA)" } 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)" } //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)" } //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)" } //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" } //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)" } //Simulator else if platform == "i386" { return "Simulator" } else if platform == "x86_64" { return "Simulator"} return platform } 

Vy mojete prototirovat егo, используя sледующий код:

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

Məqsəd-C

Objective-C kodu yenə yeni qurulmuşdur

Sys / sysctl.h 'yi unutmayın

  #import <sys/sysctl.h> - (NSString *) userDeviceName { size_t size; sysctlbyname("hw.machine", NULL,  NULL, 0); char *machine = malloc(size); sysctlbyname("hw.machine", machine,  NULL, 0); NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding]; free(machine); //iPhone if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone (1st generation)"; 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, 2nd revision)"; if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4 (Verizon)"; if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S"; if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5 (GSM)"; if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (GSM+CDMA)"; if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c (GSM)"; if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c (GSM+CDMA)"; if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s (GSM)"; if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s (GSM+CDMA)"; if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6"; if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus"; if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s"; if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus"; if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhone SE"; if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone 7 (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)"; //iPod Touch 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"; //iPad if ([platform isEqualToString:@"iPad1,1"]) return @"iPad (1st generation)"; if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2 (Wi-Fi)"; if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)"; if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)"; if ([platform isEqualToString:@"iPad2,4"]) return @"iPad 2 (Wi-Fi, Mid 2012)"; if ([platform isEqualToString:@"iPad2,5"]) return @"iPad Mini (Wi-Fi)"; if ([platform isEqualToString:@"iPad2,6"]) return @"iPad Mini (GSM)"; if ([platform isEqualToString:@"iPad2,7"]) return @"iPad Mini (GSM+CDMA)"; if ([platform isEqualToString:@"iPad3,1"]) return @"iPad (3rd generation) (Wi-Fi)"; if ([platform isEqualToString:@"iPad3,2"]) return @"iPad (3rd generation) (GSM+CDMA)"; if ([platform isEqualToString:@"iPad3,3"]) return @"iPad (3rd generation) (GSM)"; 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:@"iPad4,1"]) return @"iPad Air (Wi-Fi)"; if ([platform isEqualToString:@"iPad4,2"]) return @"iPad Air (Cellular)"; if ([platform isEqualToString:@"iPad4,3"]) return @"iPad Air (China)"; if ([platform isEqualToString:@"iPad4,4"]) return @"iPad Mini 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:@"iPad5,3"]) return @"iPad Air 2 (Wi-Fi)"; if ([platform isEqualToString:@"iPad5,4"]) return @"iPad Air 2 (Cellular)"; if ([platform isEqualToString:@"iPad6,3"]) return @"iPad Pro 9.7\" (Wi-Fi)"; if ([platform isEqualToString:@"iPad6,4"]) return @"iPad Pro 9.7\" (Cellular)"; if ([platform isEqualToString:@"iPad6,7"]) return @"iPad Pro 12.9\" (Wi-Fi)"; if ([platform isEqualToString:@"iPad6,8"]) return @"iPad Pro 12.9\" (Cellular)"; if ([platform isEqualToString:@"iPad6,11"]) return @"iPad (5th generation) (Wi-Fi)"; if ([platform isEqualToString:@"iPad6,12"]) return @"iPad (5th generation) (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)"; //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"; //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)"; //Simulator if ([platform isEqualToString:@"i386"]) return @"Simulator"; if ([platform isEqualToString:@"x86_64"]) return @"Simulator"; return platform; } 

Vy mojete prototirovat егo, используя sледующий код:

 NSLog(@"Current device is: %@", [self userDeviceName]); 
26
19 апр. ответ дан D1mers0n 19 aprel . 2016-04-19 14:55 '16 v 14:55 2016-04-19 14:55

İPad iPad Air 2iPad mini 3 üçün hazırlanmış platforma platformaları:

 - (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; } 
14
24 дек. otvet dan uplearnedu.com 24 dek. 2014-12-24 03:39 '14 в 3:39 2014-12-24 03:39

Daha çox удобный

 #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,  NULL, 0); machine = malloc(len); sysctl(mib, 2, machine,  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"); 
12
18 окт. UIBuilder'dan cavab 18 oktyabr . 2010-10-18 13:39 '10 в 13:39 2010-10-18 13:39

Здесь небольшое обновление с новыми моделями:

 - (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; } 
10
23 июля '10 в 21:55 2010-07-23 21:55 ответ от snibbe 23 İyul '10 в 21:55 2010-07-23 21:55

Я знаю, что ответ уже был отмечен, но для справки в будущем вы всегда можете размер экрана устройства, чтобы выяснить, какое устройство оно выглядит так:

 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."); } 
10
05 июня '15 в 14:34 2015-06-05 14:34 Cavab verməkdən imtina edin

Sadəcə olaraq iPhone 4S kodu qurğusu ...

iPhone 4S vernik stoku @ "iPhone4,1".

8
06 нояб. ответ дан Jason Fuerstenberg 06 нояб. 2011-11-06 03:35 '11 v 3:35 2011-11-06 03:35

Bu günə qədər, əgər yeni versiya alındı, siz identifikator ilə sonuncu nou-xau

 - (NSString *)getModel { size_t size; sysctlbyname("hw.machine", NULL,  NULL, 0); char *model = malloc(size); sysctlbyname("hw.machine", model,  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 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; } 
6
ответ дан Rodrigo 12 дек. '11 в 20:57 2011-12-12 20:57