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 11#import "UIDevice+RTCDevice.h" 12 13#import <sys/utsname.h> 14#include <memory> 15 16@implementation UIDevice (RTCDevice) 17 18+ (RTCDeviceType)deviceType { 19 NSDictionary *machineNameToType = @{ 20 @"iPhone1,1" : @(RTCDeviceTypeIPhone1G), 21 @"iPhone1,2" : @(RTCDeviceTypeIPhone3G), 22 @"iPhone2,1" : @(RTCDeviceTypeIPhone3GS), 23 @"iPhone3,1" : @(RTCDeviceTypeIPhone4), 24 @"iPhone3,2" : @(RTCDeviceTypeIPhone4), 25 @"iPhone3,3" : @(RTCDeviceTypeIPhone4Verizon), 26 @"iPhone4,1" : @(RTCDeviceTypeIPhone4S), 27 @"iPhone5,1" : @(RTCDeviceTypeIPhone5GSM), 28 @"iPhone5,2" : @(RTCDeviceTypeIPhone5GSM_CDMA), 29 @"iPhone5,3" : @(RTCDeviceTypeIPhone5CGSM), 30 @"iPhone5,4" : @(RTCDeviceTypeIPhone5CGSM_CDMA), 31 @"iPhone6,1" : @(RTCDeviceTypeIPhone5SGSM), 32 @"iPhone6,2" : @(RTCDeviceTypeIPhone5SGSM_CDMA), 33 @"iPhone7,1" : @(RTCDeviceTypeIPhone6Plus), 34 @"iPhone7,2" : @(RTCDeviceTypeIPhone6), 35 @"iPhone8,1" : @(RTCDeviceTypeIPhone6S), 36 @"iPhone8,2" : @(RTCDeviceTypeIPhone6SPlus), 37 @"iPhone8,4" : @(RTCDeviceTypeIPhoneSE), 38 @"iPhone9,1" : @(RTCDeviceTypeIPhone7), 39 @"iPhone9,2" : @(RTCDeviceTypeIPhone7Plus), 40 @"iPhone9,3" : @(RTCDeviceTypeIPhone7), 41 @"iPhone9,4" : @(RTCDeviceTypeIPhone7Plus), 42 @"iPhone10,1" : @(RTCDeviceTypeIPhone8), 43 @"iPhone10,2" : @(RTCDeviceTypeIPhone8Plus), 44 @"iPhone10,3" : @(RTCDeviceTypeIPhoneX), 45 @"iPhone10,4" : @(RTCDeviceTypeIPhone8), 46 @"iPhone10,5" : @(RTCDeviceTypeIPhone8Plus), 47 @"iPhone10,6" : @(RTCDeviceTypeIPhoneX), 48 @"iPhone11,2" : @(RTCDeviceTypeIPhoneXS), 49 @"iPhone11,4" : @(RTCDeviceTypeIPhoneXSMax), 50 @"iPhone11,6" : @(RTCDeviceTypeIPhoneXSMax), 51 @"iPhone11,8" : @(RTCDeviceTypeIPhoneXR), 52 @"iPhone12,1" : @(RTCDeviceTypeIPhone11), 53 @"iPhone12,3" : @(RTCDeviceTypeIPhone11Pro), 54 @"iPhone12,5" : @(RTCDeviceTypeIPhone11ProMax), 55 @"iPod1,1" : @(RTCDeviceTypeIPodTouch1G), 56 @"iPod2,1" : @(RTCDeviceTypeIPodTouch2G), 57 @"iPod3,1" : @(RTCDeviceTypeIPodTouch3G), 58 @"iPod4,1" : @(RTCDeviceTypeIPodTouch4G), 59 @"iPod5,1" : @(RTCDeviceTypeIPodTouch5G), 60 @"iPod7,1" : @(RTCDeviceTypeIPodTouch6G), 61 @"iPod9,1" : @(RTCDeviceTypeIPodTouch7G), 62 @"iPad1,1" : @(RTCDeviceTypeIPad), 63 @"iPad2,1" : @(RTCDeviceTypeIPad2Wifi), 64 @"iPad2,2" : @(RTCDeviceTypeIPad2GSM), 65 @"iPad2,3" : @(RTCDeviceTypeIPad2CDMA), 66 @"iPad2,4" : @(RTCDeviceTypeIPad2Wifi2), 67 @"iPad2,5" : @(RTCDeviceTypeIPadMiniWifi), 68 @"iPad2,6" : @(RTCDeviceTypeIPadMiniGSM), 69 @"iPad2,7" : @(RTCDeviceTypeIPadMiniGSM_CDMA), 70 @"iPad3,1" : @(RTCDeviceTypeIPad3Wifi), 71 @"iPad3,2" : @(RTCDeviceTypeIPad3GSM_CDMA), 72 @"iPad3,3" : @(RTCDeviceTypeIPad3GSM), 73 @"iPad3,4" : @(RTCDeviceTypeIPad4Wifi), 74 @"iPad3,5" : @(RTCDeviceTypeIPad4GSM), 75 @"iPad3,6" : @(RTCDeviceTypeIPad4GSM_CDMA), 76 @"iPad4,1" : @(RTCDeviceTypeIPadAirWifi), 77 @"iPad4,2" : @(RTCDeviceTypeIPadAirCellular), 78 @"iPad4,3" : @(RTCDeviceTypeIPadAirWifiCellular), 79 @"iPad4,4" : @(RTCDeviceTypeIPadMini2GWifi), 80 @"iPad4,5" : @(RTCDeviceTypeIPadMini2GCellular), 81 @"iPad4,6" : @(RTCDeviceTypeIPadMini2GWifiCellular), 82 @"iPad4,7" : @(RTCDeviceTypeIPadMini3), 83 @"iPad4,8" : @(RTCDeviceTypeIPadMini3), 84 @"iPad4,9" : @(RTCDeviceTypeIPadMini3), 85 @"iPad5,1" : @(RTCDeviceTypeIPadMini4), 86 @"iPad5,2" : @(RTCDeviceTypeIPadMini4), 87 @"iPad5,3" : @(RTCDeviceTypeIPadAir2), 88 @"iPad5,4" : @(RTCDeviceTypeIPadAir2), 89 @"iPad6,3" : @(RTCDeviceTypeIPadPro9Inch), 90 @"iPad6,4" : @(RTCDeviceTypeIPadPro9Inch), 91 @"iPad6,7" : @(RTCDeviceTypeIPadPro12Inch), 92 @"iPad6,8" : @(RTCDeviceTypeIPadPro12Inch), 93 @"iPad6,11" : @(RTCDeviceTypeIPad5), 94 @"iPad6,12" : @(RTCDeviceTypeIPad5), 95 @"iPad7,1" : @(RTCDeviceTypeIPadPro12Inch2), 96 @"iPad7,2" : @(RTCDeviceTypeIPadPro12Inch2), 97 @"iPad7,3" : @(RTCDeviceTypeIPadPro10Inch), 98 @"iPad7,4" : @(RTCDeviceTypeIPadPro10Inch), 99 @"iPad7,5" : @(RTCDeviceTypeIPad6), 100 @"iPad7,6" : @(RTCDeviceTypeIPad6), 101 @"iPad7,11" : @(RTCDeviceTypeIPad7Gen10Inch), 102 @"iPad7,12" : @(RTCDeviceTypeIPad7Gen10Inch), 103 @"iPad8,1" : @(RTCDeviceTypeIPadPro3Gen11Inch), 104 @"iPad8,2" : @(RTCDeviceTypeIPadPro3Gen11Inch), 105 @"iPad8,3" : @(RTCDeviceTypeIPadPro3Gen11Inch), 106 @"iPad8,4" : @(RTCDeviceTypeIPadPro3Gen11Inch), 107 @"iPad8,5" : @(RTCDeviceTypeIPadPro3Gen12Inch), 108 @"iPad8,6" : @(RTCDeviceTypeIPadPro3Gen12Inch), 109 @"iPad8,7" : @(RTCDeviceTypeIPadPro3Gen12Inch), 110 @"iPad8,8" : @(RTCDeviceTypeIPadPro3Gen12Inch), 111 @"iPad11,1" : @(RTCDeviceTypeIPadMini5Gen), 112 @"iPad11,2" : @(RTCDeviceTypeIPadMini5Gen), 113 @"iPad11,3" : @(RTCDeviceTypeIPadAir3Gen), 114 @"iPad11,4" : @(RTCDeviceTypeIPadAir3Gen), 115 @"i386" : @(RTCDeviceTypeSimulatori386), 116 @"x86_64" : @(RTCDeviceTypeSimulatorx86_64), 117 }; 118 119 RTCDeviceType deviceType = RTCDeviceTypeUnknown; 120 NSNumber *typeNumber = machineNameToType[[self machineName]]; 121 if (typeNumber) { 122 deviceType = static_cast<RTCDeviceType>(typeNumber.integerValue); 123 } 124 return deviceType; 125} 126 127+ (NSString *)machineName { 128 struct utsname systemInfo; 129 uname(&systemInfo); 130 return [[NSString alloc] initWithCString:systemInfo.machine 131 encoding:NSUTF8StringEncoding]; 132} 133 134+ (double)currentDeviceSystemVersion { 135 return [self currentDevice].systemVersion.doubleValue; 136} 137 138+ (BOOL)isIOS11OrLater { 139 return [self currentDeviceSystemVersion] >= 11.0; 140} 141 142@end 143