blob: 9b39b99b5ce04ab2f8268296899ac5946be7f067 [file] [log] [blame]
tkchind7629102016-07-28 14:52:55 -07001/*
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 Carlsson7bca8ca2018-08-30 09:30:29 +020011#import "UIDevice+RTCDevice.h"
tkchind7629102016-07-28 14:52:55 -070012
Kári Tristan Helgason0a1140e2017-10-05 13:18:14 +020013#import <sys/utsname.h>
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020014#include <memory>
tkchind7629102016-07-28 14:52:55 -070015
16@implementation UIDevice (RTCDevice)
17
18+ (RTCDeviceType)deviceType {
19 NSDictionary *machineNameToType = @{
Yura Yaroshevichc6de47e2018-10-23 16:55:04 +030020 @"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),
Yura Yaroshevichde365952019-10-31 12:01:53 +030052 @"iPhone12,1" : @(RTCDeviceTypeIPhone11),
53 @"iPhone12,3" : @(RTCDeviceTypeIPhone11Pro),
54 @"iPhone12,5" : @(RTCDeviceTypeIPhone11ProMax),
Dave Cowartb853d722021-01-19 15:29:11 -060055 @"iPhone13,1" : @(RTCDeviceTypeIPhone12Mini),
56 @"iPhone13,2" : @(RTCDeviceTypeIPhone12),
57 @"iPhone13,3" : @(RTCDeviceTypeIPhone12Pro),
58 @"iPhone13,4" : @(RTCDeviceTypeIPhone12ProMax),
Yura Yaroshevichc6de47e2018-10-23 16:55:04 +030059 @"iPod1,1" : @(RTCDeviceTypeIPodTouch1G),
60 @"iPod2,1" : @(RTCDeviceTypeIPodTouch2G),
61 @"iPod3,1" : @(RTCDeviceTypeIPodTouch3G),
62 @"iPod4,1" : @(RTCDeviceTypeIPodTouch4G),
63 @"iPod5,1" : @(RTCDeviceTypeIPodTouch5G),
64 @"iPod7,1" : @(RTCDeviceTypeIPodTouch6G),
Yura Yaroshevichde365952019-10-31 12:01:53 +030065 @"iPod9,1" : @(RTCDeviceTypeIPodTouch7G),
Yura Yaroshevichc6de47e2018-10-23 16:55:04 +030066 @"iPad1,1" : @(RTCDeviceTypeIPad),
67 @"iPad2,1" : @(RTCDeviceTypeIPad2Wifi),
68 @"iPad2,2" : @(RTCDeviceTypeIPad2GSM),
69 @"iPad2,3" : @(RTCDeviceTypeIPad2CDMA),
70 @"iPad2,4" : @(RTCDeviceTypeIPad2Wifi2),
71 @"iPad2,5" : @(RTCDeviceTypeIPadMiniWifi),
72 @"iPad2,6" : @(RTCDeviceTypeIPadMiniGSM),
73 @"iPad2,7" : @(RTCDeviceTypeIPadMiniGSM_CDMA),
74 @"iPad3,1" : @(RTCDeviceTypeIPad3Wifi),
75 @"iPad3,2" : @(RTCDeviceTypeIPad3GSM_CDMA),
76 @"iPad3,3" : @(RTCDeviceTypeIPad3GSM),
77 @"iPad3,4" : @(RTCDeviceTypeIPad4Wifi),
78 @"iPad3,5" : @(RTCDeviceTypeIPad4GSM),
79 @"iPad3,6" : @(RTCDeviceTypeIPad4GSM_CDMA),
80 @"iPad4,1" : @(RTCDeviceTypeIPadAirWifi),
81 @"iPad4,2" : @(RTCDeviceTypeIPadAirCellular),
82 @"iPad4,3" : @(RTCDeviceTypeIPadAirWifiCellular),
83 @"iPad4,4" : @(RTCDeviceTypeIPadMini2GWifi),
84 @"iPad4,5" : @(RTCDeviceTypeIPadMini2GCellular),
85 @"iPad4,6" : @(RTCDeviceTypeIPadMini2GWifiCellular),
86 @"iPad4,7" : @(RTCDeviceTypeIPadMini3),
87 @"iPad4,8" : @(RTCDeviceTypeIPadMini3),
88 @"iPad4,9" : @(RTCDeviceTypeIPadMini3),
89 @"iPad5,1" : @(RTCDeviceTypeIPadMini4),
90 @"iPad5,2" : @(RTCDeviceTypeIPadMini4),
91 @"iPad5,3" : @(RTCDeviceTypeIPadAir2),
92 @"iPad5,4" : @(RTCDeviceTypeIPadAir2),
93 @"iPad6,3" : @(RTCDeviceTypeIPadPro9Inch),
94 @"iPad6,4" : @(RTCDeviceTypeIPadPro9Inch),
95 @"iPad6,7" : @(RTCDeviceTypeIPadPro12Inch),
96 @"iPad6,8" : @(RTCDeviceTypeIPadPro12Inch),
97 @"iPad6,11" : @(RTCDeviceTypeIPad5),
98 @"iPad6,12" : @(RTCDeviceTypeIPad5),
99 @"iPad7,1" : @(RTCDeviceTypeIPadPro12Inch2),
100 @"iPad7,2" : @(RTCDeviceTypeIPadPro12Inch2),
101 @"iPad7,3" : @(RTCDeviceTypeIPadPro10Inch),
102 @"iPad7,4" : @(RTCDeviceTypeIPadPro10Inch),
103 @"iPad7,5" : @(RTCDeviceTypeIPad6),
104 @"iPad7,6" : @(RTCDeviceTypeIPad6),
Yura Yaroshevichde365952019-10-31 12:01:53 +0300105 @"iPad7,11" : @(RTCDeviceTypeIPad7Gen10Inch),
106 @"iPad7,12" : @(RTCDeviceTypeIPad7Gen10Inch),
107 @"iPad8,1" : @(RTCDeviceTypeIPadPro3Gen11Inch),
108 @"iPad8,2" : @(RTCDeviceTypeIPadPro3Gen11Inch),
109 @"iPad8,3" : @(RTCDeviceTypeIPadPro3Gen11Inch),
110 @"iPad8,4" : @(RTCDeviceTypeIPadPro3Gen11Inch),
111 @"iPad8,5" : @(RTCDeviceTypeIPadPro3Gen12Inch),
112 @"iPad8,6" : @(RTCDeviceTypeIPadPro3Gen12Inch),
113 @"iPad8,7" : @(RTCDeviceTypeIPadPro3Gen12Inch),
114 @"iPad8,8" : @(RTCDeviceTypeIPadPro3Gen12Inch),
Dave Cowartb853d722021-01-19 15:29:11 -0600115 @"iPad8,9" : @(RTCDeviceTypeIPadPro4Gen11Inch),
116 @"iPad8,10" : @(RTCDeviceTypeIPadPro4Gen11Inch),
117 @"iPad8,11" : @(RTCDeviceTypeIPadPro4Gen12Inch),
118 @"iPad8,12" : @(RTCDeviceTypeIPadPro4Gen12Inch),
Yura Yaroshevichde365952019-10-31 12:01:53 +0300119 @"iPad11,1" : @(RTCDeviceTypeIPadMini5Gen),
120 @"iPad11,2" : @(RTCDeviceTypeIPadMini5Gen),
121 @"iPad11,3" : @(RTCDeviceTypeIPadAir3Gen),
122 @"iPad11,4" : @(RTCDeviceTypeIPadAir3Gen),
Dave Cowartb853d722021-01-19 15:29:11 -0600123 @"iPad11,6" : @(RTCDeviceTypeIPad8),
124 @"iPad11,7" : @(RTCDeviceTypeIPad8),
125 @"iPad13,1" : @(RTCDeviceTypeIPadAir4Gen),
126 @"iPad12,2" : @(RTCDeviceTypeIPadAir4Gen),
Yura Yaroshevichc6de47e2018-10-23 16:55:04 +0300127 @"i386" : @(RTCDeviceTypeSimulatori386),
128 @"x86_64" : @(RTCDeviceTypeSimulatorx86_64),
tkchind7629102016-07-28 14:52:55 -0700129 };
130
tkchind7629102016-07-28 14:52:55 -0700131 RTCDeviceType deviceType = RTCDeviceTypeUnknown;
Kári Tristan Helgason0a1140e2017-10-05 13:18:14 +0200132 NSNumber *typeNumber = machineNameToType[[self machineName]];
tkchind7629102016-07-28 14:52:55 -0700133 if (typeNumber) {
134 deviceType = static_cast<RTCDeviceType>(typeNumber.integerValue);
135 }
136 return deviceType;
137}
138
Kári Tristan Helgason0a1140e2017-10-05 13:18:14 +0200139+ (NSString *)machineName {
140 struct utsname systemInfo;
141 uname(&systemInfo);
142 return [[NSString alloc] initWithCString:systemInfo.machine
143 encoding:NSUTF8StringEncoding];
tkchind7629102016-07-28 14:52:55 -0700144}
145
sdkdimon846e1be2017-03-06 16:42:19 -0800146+ (double)currentDeviceSystemVersion {
147 return [self currentDevice].systemVersion.doubleValue;
148}
149
JT Teha6368d12017-09-28 11:00:39 -0700150+ (BOOL)isIOS11OrLater {
151 return [self currentDeviceSystemVersion] >= 11.0;
152}
153
tkchind7629102016-07-28 14:52:55 -0700154@end