tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 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 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 11 | #import "UIDevice+RTCDevice.h" |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 12 | |
Kári Tristan Helgason | 0a1140e | 2017-10-05 13:18:14 +0200 | [diff] [blame] | 13 | #import <sys/utsname.h> |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 14 | #include <memory> |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 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), |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 24 | @"iPhone3,2": @(RTCDeviceTypeIPhone4), |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 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), |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 37 | @"iPhone8,4": @(RTCDeviceTypeIPhoneSE), |
Kári Tristan Helgason | 0a1140e | 2017-10-05 13:18:14 +0200 | [diff] [blame] | 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), |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 48 | @"iPod1,1": @(RTCDeviceTypeIPodTouch1G), |
| 49 | @"iPod2,1": @(RTCDeviceTypeIPodTouch2G), |
| 50 | @"iPod3,1": @(RTCDeviceTypeIPodTouch3G), |
| 51 | @"iPod4,1": @(RTCDeviceTypeIPodTouch4G), |
| 52 | @"iPod5,1": @(RTCDeviceTypeIPodTouch5G), |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 53 | @"iPod7,1": @(RTCDeviceTypeIPodTouch6G), |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 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), |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 70 | @"iPad4,3": @(RTCDeviceTypeIPadAirWifiCellular), |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 71 | @"iPad4,4": @(RTCDeviceTypeIPadMini2GWifi), |
| 72 | @"iPad4,5": @(RTCDeviceTypeIPadMini2GCellular), |
Yura Yaroshevich | 0f77fea | 2018-04-26 15:41:01 +0300 | [diff] [blame] | 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), |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 93 | @"i386": @(RTCDeviceTypeSimulatori386), |
| 94 | @"x86_64": @(RTCDeviceTypeSimulatorx86_64), |
| 95 | }; |
| 96 | |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 97 | RTCDeviceType deviceType = RTCDeviceTypeUnknown; |
Kári Tristan Helgason | 0a1140e | 2017-10-05 13:18:14 +0200 | [diff] [blame] | 98 | NSNumber *typeNumber = machineNameToType[[self machineName]]; |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 99 | if (typeNumber) { |
| 100 | deviceType = static_cast<RTCDeviceType>(typeNumber.integerValue); |
| 101 | } |
| 102 | return deviceType; |
| 103 | } |
| 104 | |
Kári Tristan Helgason | 0a1140e | 2017-10-05 13:18:14 +0200 | [diff] [blame] | 105 | + (NSString *)machineName { |
| 106 | struct utsname systemInfo; |
| 107 | uname(&systemInfo); |
| 108 | return [[NSString alloc] initWithCString:systemInfo.machine |
| 109 | encoding:NSUTF8StringEncoding]; |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 110 | } |
| 111 | |
sdkdimon | 846e1be | 2017-03-06 16:42:19 -0800 | [diff] [blame] | 112 | + (double)currentDeviceSystemVersion { |
| 113 | return [self currentDevice].systemVersion.doubleValue; |
| 114 | } |
| 115 | |
JT Teh | a6368d1 | 2017-09-28 11:00:39 -0700 | [diff] [blame] | 116 | + (BOOL)isIOS11OrLater { |
| 117 | return [self currentDeviceSystemVersion] >= 11.0; |
| 118 | } |
| 119 | |
tkchin | d762910 | 2016-07-28 14:52:55 -0700 | [diff] [blame] | 120 | @end |