OLD | NEW |
(Empty) | |
| 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 "WebRTC/UIDevice+RTCDevice.h" |
| 12 |
| 13 #include <memory> |
| 14 #include <sys/sysctl.h> |
| 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,3": @(RTCDeviceTypeIPhone4Verizon), |
| 25 @"iPhone4,1": @(RTCDeviceTypeIPhone4S), |
| 26 @"iPhone5,1": @(RTCDeviceTypeIPhone5GSM), |
| 27 @"iPhone5,2": @(RTCDeviceTypeIPhone5GSM_CDMA), |
| 28 @"iPhone5,3": @(RTCDeviceTypeIPhone5CGSM), |
| 29 @"iPhone5,4": @(RTCDeviceTypeIPhone5CGSM_CDMA), |
| 30 @"iPhone6,1": @(RTCDeviceTypeIPhone5SGSM), |
| 31 @"iPhone6,2": @(RTCDeviceTypeIPhone5SGSM_CDMA), |
| 32 @"iPhone7,1": @(RTCDeviceTypeIPhone6Plus), |
| 33 @"iPhone7,2": @(RTCDeviceTypeIPhone6), |
| 34 @"iPhone8,1": @(RTCDeviceTypeIPhone6S), |
| 35 @"iPhone8,2": @(RTCDeviceTypeIPhone6SPlus), |
| 36 @"iPod1,1": @(RTCDeviceTypeIPodTouch1G), |
| 37 @"iPod2,1": @(RTCDeviceTypeIPodTouch2G), |
| 38 @"iPod3,1": @(RTCDeviceTypeIPodTouch3G), |
| 39 @"iPod4,1": @(RTCDeviceTypeIPodTouch4G), |
| 40 @"iPod5,1": @(RTCDeviceTypeIPodTouch5G), |
| 41 @"iPad1,1": @(RTCDeviceTypeIPad), |
| 42 @"iPad2,1": @(RTCDeviceTypeIPad2Wifi), |
| 43 @"iPad2,2": @(RTCDeviceTypeIPad2GSM), |
| 44 @"iPad2,3": @(RTCDeviceTypeIPad2CDMA), |
| 45 @"iPad2,4": @(RTCDeviceTypeIPad2Wifi2), |
| 46 @"iPad2,5": @(RTCDeviceTypeIPadMiniWifi), |
| 47 @"iPad2,6": @(RTCDeviceTypeIPadMiniGSM), |
| 48 @"iPad2,7": @(RTCDeviceTypeIPadMiniGSM_CDMA), |
| 49 @"iPad3,1": @(RTCDeviceTypeIPad3Wifi), |
| 50 @"iPad3,2": @(RTCDeviceTypeIPad3GSM_CDMA), |
| 51 @"iPad3,3": @(RTCDeviceTypeIPad3GSM), |
| 52 @"iPad3,4": @(RTCDeviceTypeIPad4Wifi), |
| 53 @"iPad3,5": @(RTCDeviceTypeIPad4GSM), |
| 54 @"iPad3,6": @(RTCDeviceTypeIPad4GSM_CDMA), |
| 55 @"iPad4,1": @(RTCDeviceTypeIPadAirWifi), |
| 56 @"iPad4,2": @(RTCDeviceTypeIPadAirCellular), |
| 57 @"iPad4,4": @(RTCDeviceTypeIPadMini2GWifi), |
| 58 @"iPad4,5": @(RTCDeviceTypeIPadMini2GCellular), |
| 59 @"i386": @(RTCDeviceTypeSimulatori386), |
| 60 @"x86_64": @(RTCDeviceTypeSimulatorx86_64), |
| 61 }; |
| 62 |
| 63 size_t size = 0; |
| 64 sysctlbyname("hw.machine", NULL, &size, NULL, 0); |
| 65 std::unique_ptr<char[]> machine; |
| 66 machine.reset(new char[size]); |
| 67 sysctlbyname("hw.machine", machine.get(), &size, NULL, 0); |
| 68 NSString *machineName = [[NSString alloc] initWithCString:machine.get() |
| 69 encoding:NSUTF8StringEncoding
]; |
| 70 RTCDeviceType deviceType = RTCDeviceTypeUnknown; |
| 71 NSNumber *typeNumber = machineNameToType[machineName]; |
| 72 if (typeNumber) { |
| 73 deviceType = static_cast<RTCDeviceType>(typeNumber.integerValue); |
| 74 } |
| 75 return deviceType; |
| 76 } |
| 77 |
| 78 + (NSString *)stringForDeviceType:(RTCDeviceType)deviceType { |
| 79 switch (deviceType) { |
| 80 case RTCDeviceTypeUnknown: |
| 81 return @"Unknown"; |
| 82 case RTCDeviceTypeIPhone1G: |
| 83 return @"iPhone 1G"; |
| 84 case RTCDeviceTypeIPhone3G: |
| 85 return @"iPhone 3G"; |
| 86 case RTCDeviceTypeIPhone3GS: |
| 87 return @"iPhone 3GS"; |
| 88 case RTCDeviceTypeIPhone4: |
| 89 return @"iPhone 4"; |
| 90 case RTCDeviceTypeIPhone4Verizon: |
| 91 return @"iPhone 4 Verizon"; |
| 92 case RTCDeviceTypeIPhone4S: |
| 93 return @"iPhone 4S"; |
| 94 case RTCDeviceTypeIPhone5GSM: |
| 95 return @"iPhone 5 (GSM)"; |
| 96 case RTCDeviceTypeIPhone5GSM_CDMA: |
| 97 return @"iPhone 5 (GSM+CDMA)"; |
| 98 case RTCDeviceTypeIPhone5CGSM: |
| 99 return @"iPhone 5C (GSM)"; |
| 100 case RTCDeviceTypeIPhone5CGSM_CDMA: |
| 101 return @"iPhone 5C (GSM+CDMA)"; |
| 102 case RTCDeviceTypeIPhone5SGSM: |
| 103 return @"iPhone 5S (GSM)"; |
| 104 case RTCDeviceTypeIPhone5SGSM_CDMA: |
| 105 return @"iPhone 5S (GSM+CDMA)"; |
| 106 case RTCDeviceTypeIPhone6Plus: |
| 107 return @"iPhone 6 Plus"; |
| 108 case RTCDeviceTypeIPhone6: |
| 109 return @"iPhone 6"; |
| 110 case RTCDeviceTypeIPhone6S: |
| 111 return @"iPhone 6S"; |
| 112 case RTCDeviceTypeIPhone6SPlus: |
| 113 return @"iPhone 6S Plus"; |
| 114 case RTCDeviceTypeIPodTouch1G: |
| 115 return @"iPod Touch 1G"; |
| 116 case RTCDeviceTypeIPodTouch2G: |
| 117 return @"iPod Touch 2G"; |
| 118 case RTCDeviceTypeIPodTouch3G: |
| 119 return @"iPod Touch 3G"; |
| 120 case RTCDeviceTypeIPodTouch4G: |
| 121 return @"iPod Touch 4G"; |
| 122 case RTCDeviceTypeIPodTouch5G: |
| 123 return @"iPod Touch 5G"; |
| 124 case RTCDeviceTypeIPad: |
| 125 return @"iPad"; |
| 126 case RTCDeviceTypeIPad2Wifi: |
| 127 return @"iPad 2 (WiFi)"; |
| 128 case RTCDeviceTypeIPad2GSM: |
| 129 return @"iPad 2 (GSM)"; |
| 130 case RTCDeviceTypeIPad2CDMA: |
| 131 return @"iPad 2 (CDMA)"; |
| 132 case RTCDeviceTypeIPad2Wifi2: |
| 133 return @"iPad 2 (WiFi) 2"; |
| 134 case RTCDeviceTypeIPadMiniWifi: |
| 135 return @"iPad Mini (WiFi)"; |
| 136 case RTCDeviceTypeIPadMiniGSM: |
| 137 return @"iPad Mini (GSM)"; |
| 138 case RTCDeviceTypeIPadMiniGSM_CDMA: |
| 139 return @"iPad Mini (GSM+CDMA)"; |
| 140 case RTCDeviceTypeIPad3Wifi: |
| 141 return @"iPad 3 (WiFi)"; |
| 142 case RTCDeviceTypeIPad3GSM_CDMA: |
| 143 return @"iPad 3 (GSM+CDMA)"; |
| 144 case RTCDeviceTypeIPad3GSM: |
| 145 return @"iPad 3 (GSM)"; |
| 146 case RTCDeviceTypeIPad4Wifi: |
| 147 return @"iPad 4 (WiFi)"; |
| 148 case RTCDeviceTypeIPad4GSM: |
| 149 return @"iPad 4 (GSM)"; |
| 150 case RTCDeviceTypeIPad4GSM_CDMA: |
| 151 return @"iPad 4 (GSM+CDMA)"; |
| 152 case RTCDeviceTypeIPadAirWifi: |
| 153 return @"iPad Air (WiFi)"; |
| 154 case RTCDeviceTypeIPadAirCellular: |
| 155 return @"iPad Air (Cellular)"; |
| 156 case RTCDeviceTypeIPadMini2GWifi: |
| 157 return @"iPad Mini 2G (Wifi)"; |
| 158 case RTCDeviceTypeIPadMini2GCellular: |
| 159 return @"iPad Mini 2G (Cellular)"; |
| 160 case RTCDeviceTypeSimulatori386: |
| 161 return @"i386 Simulator"; |
| 162 case RTCDeviceTypeSimulatorx86_64: |
| 163 return @"x86_64 Simulator"; |
| 164 } |
| 165 return @"Unknown"; |
| 166 } |
| 167 |
| 168 + (double)currentDeviceSystemVersion { |
| 169 return [self currentDevice].systemVersion.doubleValue; |
| 170 } |
| 171 |
| 172 + (BOOL)isIOS9OrLater { |
| 173 return [self currentDeviceSystemVersion] >= 9.0; |
| 174 } |
| 175 |
| 176 @end |
OLD | NEW |