You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2016 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #import "UIDevice+RTCDevice.h"
  11. #import <sys/utsname.h>
  12. #include <memory>
  13. @implementation UIDevice (RTCDevice)
  14. + (RTCDeviceType)deviceType {
  15. NSDictionary *machineNameToType = @{
  16. @"iPhone1,1" : @(RTCDeviceTypeIPhone1G),
  17. @"iPhone1,2" : @(RTCDeviceTypeIPhone3G),
  18. @"iPhone2,1" : @(RTCDeviceTypeIPhone3GS),
  19. @"iPhone3,1" : @(RTCDeviceTypeIPhone4),
  20. @"iPhone3,2" : @(RTCDeviceTypeIPhone4),
  21. @"iPhone3,3" : @(RTCDeviceTypeIPhone4Verizon),
  22. @"iPhone4,1" : @(RTCDeviceTypeIPhone4S),
  23. @"iPhone5,1" : @(RTCDeviceTypeIPhone5GSM),
  24. @"iPhone5,2" : @(RTCDeviceTypeIPhone5GSM_CDMA),
  25. @"iPhone5,3" : @(RTCDeviceTypeIPhone5CGSM),
  26. @"iPhone5,4" : @(RTCDeviceTypeIPhone5CGSM_CDMA),
  27. @"iPhone6,1" : @(RTCDeviceTypeIPhone5SGSM),
  28. @"iPhone6,2" : @(RTCDeviceTypeIPhone5SGSM_CDMA),
  29. @"iPhone7,1" : @(RTCDeviceTypeIPhone6Plus),
  30. @"iPhone7,2" : @(RTCDeviceTypeIPhone6),
  31. @"iPhone8,1" : @(RTCDeviceTypeIPhone6S),
  32. @"iPhone8,2" : @(RTCDeviceTypeIPhone6SPlus),
  33. @"iPhone8,4" : @(RTCDeviceTypeIPhoneSE),
  34. @"iPhone9,1" : @(RTCDeviceTypeIPhone7),
  35. @"iPhone9,2" : @(RTCDeviceTypeIPhone7Plus),
  36. @"iPhone9,3" : @(RTCDeviceTypeIPhone7),
  37. @"iPhone9,4" : @(RTCDeviceTypeIPhone7Plus),
  38. @"iPhone10,1" : @(RTCDeviceTypeIPhone8),
  39. @"iPhone10,2" : @(RTCDeviceTypeIPhone8Plus),
  40. @"iPhone10,3" : @(RTCDeviceTypeIPhoneX),
  41. @"iPhone10,4" : @(RTCDeviceTypeIPhone8),
  42. @"iPhone10,5" : @(RTCDeviceTypeIPhone8Plus),
  43. @"iPhone10,6" : @(RTCDeviceTypeIPhoneX),
  44. @"iPhone11,2" : @(RTCDeviceTypeIPhoneXS),
  45. @"iPhone11,4" : @(RTCDeviceTypeIPhoneXSMax),
  46. @"iPhone11,6" : @(RTCDeviceTypeIPhoneXSMax),
  47. @"iPhone11,8" : @(RTCDeviceTypeIPhoneXR),
  48. @"iPod1,1" : @(RTCDeviceTypeIPodTouch1G),
  49. @"iPod2,1" : @(RTCDeviceTypeIPodTouch2G),
  50. @"iPod3,1" : @(RTCDeviceTypeIPodTouch3G),
  51. @"iPod4,1" : @(RTCDeviceTypeIPodTouch4G),
  52. @"iPod5,1" : @(RTCDeviceTypeIPodTouch5G),
  53. @"iPod7,1" : @(RTCDeviceTypeIPodTouch6G),
  54. @"iPad1,1" : @(RTCDeviceTypeIPad),
  55. @"iPad2,1" : @(RTCDeviceTypeIPad2Wifi),
  56. @"iPad2,2" : @(RTCDeviceTypeIPad2GSM),
  57. @"iPad2,3" : @(RTCDeviceTypeIPad2CDMA),
  58. @"iPad2,4" : @(RTCDeviceTypeIPad2Wifi2),
  59. @"iPad2,5" : @(RTCDeviceTypeIPadMiniWifi),
  60. @"iPad2,6" : @(RTCDeviceTypeIPadMiniGSM),
  61. @"iPad2,7" : @(RTCDeviceTypeIPadMiniGSM_CDMA),
  62. @"iPad3,1" : @(RTCDeviceTypeIPad3Wifi),
  63. @"iPad3,2" : @(RTCDeviceTypeIPad3GSM_CDMA),
  64. @"iPad3,3" : @(RTCDeviceTypeIPad3GSM),
  65. @"iPad3,4" : @(RTCDeviceTypeIPad4Wifi),
  66. @"iPad3,5" : @(RTCDeviceTypeIPad4GSM),
  67. @"iPad3,6" : @(RTCDeviceTypeIPad4GSM_CDMA),
  68. @"iPad4,1" : @(RTCDeviceTypeIPadAirWifi),
  69. @"iPad4,2" : @(RTCDeviceTypeIPadAirCellular),
  70. @"iPad4,3" : @(RTCDeviceTypeIPadAirWifiCellular),
  71. @"iPad4,4" : @(RTCDeviceTypeIPadMini2GWifi),
  72. @"iPad4,5" : @(RTCDeviceTypeIPadMini2GCellular),
  73. @"iPad4,6" : @(RTCDeviceTypeIPadMini2GWifiCellular),
  74. @"iPad4,7" : @(RTCDeviceTypeIPadMini3),
  75. @"iPad4,8" : @(RTCDeviceTypeIPadMini3),
  76. @"iPad4,9" : @(RTCDeviceTypeIPadMini3),
  77. @"iPad5,1" : @(RTCDeviceTypeIPadMini4),
  78. @"iPad5,2" : @(RTCDeviceTypeIPadMini4),
  79. @"iPad5,3" : @(RTCDeviceTypeIPadAir2),
  80. @"iPad5,4" : @(RTCDeviceTypeIPadAir2),
  81. @"iPad6,3" : @(RTCDeviceTypeIPadPro9Inch),
  82. @"iPad6,4" : @(RTCDeviceTypeIPadPro9Inch),
  83. @"iPad6,7" : @(RTCDeviceTypeIPadPro12Inch),
  84. @"iPad6,8" : @(RTCDeviceTypeIPadPro12Inch),
  85. @"iPad6,11" : @(RTCDeviceTypeIPad5),
  86. @"iPad6,12" : @(RTCDeviceTypeIPad5),
  87. @"iPad7,1" : @(RTCDeviceTypeIPadPro12Inch2),
  88. @"iPad7,2" : @(RTCDeviceTypeIPadPro12Inch2),
  89. @"iPad7,3" : @(RTCDeviceTypeIPadPro10Inch),
  90. @"iPad7,4" : @(RTCDeviceTypeIPadPro10Inch),
  91. @"iPad7,5" : @(RTCDeviceTypeIPad6),
  92. @"iPad7,6" : @(RTCDeviceTypeIPad6),
  93. @"i386" : @(RTCDeviceTypeSimulatori386),
  94. @"x86_64" : @(RTCDeviceTypeSimulatorx86_64),
  95. };
  96. RTCDeviceType deviceType = RTCDeviceTypeUnknown;
  97. NSNumber *typeNumber = machineNameToType[[self machineName]];
  98. if (typeNumber) {
  99. deviceType = static_cast<RTCDeviceType>(typeNumber.integerValue);
  100. }
  101. return deviceType;
  102. }
  103. + (NSString *)machineName {
  104. struct utsname systemInfo;
  105. uname(&systemInfo);
  106. return [[NSString alloc] initWithCString:systemInfo.machine
  107. encoding:NSUTF8StringEncoding];
  108. }
  109. + (double)currentDeviceSystemVersion {
  110. return [self currentDevice].systemVersion.doubleValue;
  111. }
  112. + (BOOL)isIOS11OrLater {
  113. return [self currentDeviceSystemVersion] >= 11.0;
  114. }
  115. @end