BDFaceDevice.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // BDFaceDevice.m
  3. // FaceSDKSample_IOS
  4. //
  5. // Created by Zhang,Jian(MBD) on 2020/12/9.
  6. // Copyright © 2020 Baidu. All rights reserved.
  7. //
  8. #import "BDFaceDevice.h"
  9. #import <sys/utsname.h>
  10. @implementation BDFaceDevice
  11. + (NSString*)deviceName
  12. {
  13. struct utsname systemInfo;
  14. uname(&systemInfo);
  15. NSString* code = [NSString stringWithCString:systemInfo.machine
  16. encoding:NSUTF8StringEncoding];
  17. static NSDictionary* deviceNamesByCode = nil;
  18. if (!deviceNamesByCode) {
  19. deviceNamesByCode = @{@"i386" : @"Simulator",
  20. @"x86_64" : @"Simulator",
  21. @"iPod1,1" : @"iPod Touch", // (Original)
  22. @"iPod2,1" : @"iPod Touch", // (Second Generation)
  23. @"iPod3,1" : @"iPod Touch", // (Third Generation)
  24. @"iPod4,1" : @"iPod Touch", // (Fourth Generation)
  25. @"iPod7,1" : @"iPod Touch", // (6th Generation)
  26. @"iPhone1,1" : @"iPhone", // (Original)
  27. @"iPhone1,2" : @"iPhone", // (3G)
  28. @"iPhone2,1" : @"iPhone", // (3GS)
  29. @"iPad1,1" : @"iPad", // (Original)
  30. @"iPad2,1" : @"iPad 2", //
  31. @"iPad3,1" : @"iPad", // (3rd Generation)
  32. @"iPhone3,1" : @"iPhone 4", // (GSM)
  33. @"iPhone3,3" : @"iPhone 4", // (CDMA/Verizon/Sprint)
  34. @"iPhone4,1" : @"iPhone 4S", //
  35. @"iPhone5,1" : @"iPhone 5", // (model A1428, AT&T/Canada)
  36. @"iPhone5,2" : @"iPhone 5", // (model A1429, everything else)
  37. @"iPad3,4" : @"iPad", // (4th Generation)
  38. @"iPad2,5" : @"iPad Mini", // (Original)
  39. @"iPhone5,3" : @"iPhone 5c", // (model A1456, A1532 | GSM)
  40. @"iPhone5,4" : @"iPhone 5c", // (model A1507, A1516, A1526 (China), A1529 | Global)
  41. @"iPhone6,1" : @"iPhone 5s", // (model A1433, A1533 | GSM)
  42. @"iPhone6,2" : @"iPhone 5s", // (model A1457, A1518, A1528 (China), A1530 | Global)
  43. @"iPhone7,1" : @"iPhone 6 Plus", //
  44. @"iPhone7,2" : @"iPhone 6", //
  45. @"iPhone8,1" : @"iPhone 6S", //
  46. @"iPhone8,2" : @"iPhone 6S Plus", //
  47. @"iPhone8,4" : @"iPhone SE", //
  48. @"iPhone9,1" : @"iPhone 7", //
  49. @"iPhone9,3" : @"iPhone 7", //
  50. @"iPhone9,2" : @"iPhone 7 Plus", //
  51. @"iPhone9,4" : @"iPhone 7 Plus", //
  52. @"iPhone10,1": @"iPhone 8", // CDMA
  53. @"iPhone10,4": @"iPhone 8", // GSM
  54. @"iPhone10,2": @"iPhone 8 Plus", // CDMA
  55. @"iPhone10,5": @"iPhone 8 Plus", // GSM
  56. @"iPhone10,3": @"iPhone X", // CDMA
  57. @"iPhone10,6": @"iPhone X", // GSM
  58. @"iPhone11,2": @"iPhone XS", //
  59. @"iPhone11,4": @"iPhone XS Max", //
  60. @"iPhone11,6": @"iPhone XS Max", // China
  61. @"iPhone11,8": @"iPhone XR", //
  62. @"iPhone12,1": @"iPhone 11", //
  63. @"iPhone12,3": @"iPhone 11 Pro", //
  64. @"iPhone12,5": @"iPhone 11 Pro Max", //
  65. @"iPad4,1" : @"iPad Air", // 5th Generation iPad (iPad Air) - Wifi
  66. @"iPad4,2" : @"iPad Air", // 5th Generation iPad (iPad Air) - Cellular
  67. @"iPad4,4" : @"iPad Mini", // (2nd Generation iPad Mini - Wifi)
  68. @"iPad4,5" : @"iPad Mini", // (2nd Generation iPad Mini - Cellular)
  69. @"iPad4,7" : @"iPad Mini", // (3rd Generation iPad Mini - Wifi (model A1599))
  70. @"iPad6,7" : @"iPad Pro (12.9\")", // iPad Pro 12.9 inches - (model A1584)
  71. @"iPad6,8" : @"iPad Pro (12.9\")", // iPad Pro 12.9 inches - (model A1652)
  72. @"iPad6,3" : @"iPad Pro (9.7\")", // iPad Pro 9.7 inches - (model A1673)
  73. @"iPad6,4" : @"iPad Pro (9.7\")" // iPad Pro 9.7 inches - (models A1674 and A1675)
  74. };
  75. }
  76. NSString* deviceName = [deviceNamesByCode objectForKey:code];
  77. if (!deviceName) {
  78. // Not found on database. At least guess main device type from string contents:
  79. if ([code rangeOfString:@"iPod"].location != NSNotFound) {
  80. deviceName = @"iPod Touch";
  81. }
  82. else if([code rangeOfString:@"iPad"].location != NSNotFound) {
  83. deviceName = @"iPad";
  84. }
  85. else if([code rangeOfString:@"iPhone"].location != NSNotFound){
  86. deviceName = @"iPhone";
  87. }
  88. else {
  89. deviceName = @"Unknown";
  90. }
  91. }
  92. return deviceName;
  93. }
  94. @end