blob: 6f68e9f7a0da46b04e5a979509874d6d2a3aa2f1 [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),
52 @"iPod1,1" : @(RTCDeviceTypeIPodTouch1G),
53 @"iPod2,1" : @(RTCDeviceTypeIPodTouch2G),
54 @"iPod3,1" : @(RTCDeviceTypeIPodTouch3G),
55 @"iPod4,1" : @(RTCDeviceTypeIPodTouch4G),
56 @"iPod5,1" : @(RTCDeviceTypeIPodTouch5G),
57 @"iPod7,1" : @(RTCDeviceTypeIPodTouch6G),
58 @"iPad1,1" : @(RTCDeviceTypeIPad),
59 @"iPad2,1" : @(RTCDeviceTypeIPad2Wifi),
60 @"iPad2,2" : @(RTCDeviceTypeIPad2GSM),
61 @"iPad2,3" : @(RTCDeviceTypeIPad2CDMA),
62 @"iPad2,4" : @(RTCDeviceTypeIPad2Wifi2),
63 @"iPad2,5" : @(RTCDeviceTypeIPadMiniWifi),
64 @"iPad2,6" : @(RTCDeviceTypeIPadMiniGSM),
65 @"iPad2,7" : @(RTCDeviceTypeIPadMiniGSM_CDMA),
66 @"iPad3,1" : @(RTCDeviceTypeIPad3Wifi),
67 @"iPad3,2" : @(RTCDeviceTypeIPad3GSM_CDMA),
68 @"iPad3,3" : @(RTCDeviceTypeIPad3GSM),
69 @"iPad3,4" : @(RTCDeviceTypeIPad4Wifi),
70 @"iPad3,5" : @(RTCDeviceTypeIPad4GSM),
71 @"iPad3,6" : @(RTCDeviceTypeIPad4GSM_CDMA),
72 @"iPad4,1" : @(RTCDeviceTypeIPadAirWifi),
73 @"iPad4,2" : @(RTCDeviceTypeIPadAirCellular),
74 @"iPad4,3" : @(RTCDeviceTypeIPadAirWifiCellular),
75 @"iPad4,4" : @(RTCDeviceTypeIPadMini2GWifi),
76 @"iPad4,5" : @(RTCDeviceTypeIPadMini2GCellular),
77 @"iPad4,6" : @(RTCDeviceTypeIPadMini2GWifiCellular),
78 @"iPad4,7" : @(RTCDeviceTypeIPadMini3),
79 @"iPad4,8" : @(RTCDeviceTypeIPadMini3),
80 @"iPad4,9" : @(RTCDeviceTypeIPadMini3),
81 @"iPad5,1" : @(RTCDeviceTypeIPadMini4),
82 @"iPad5,2" : @(RTCDeviceTypeIPadMini4),
83 @"iPad5,3" : @(RTCDeviceTypeIPadAir2),
84 @"iPad5,4" : @(RTCDeviceTypeIPadAir2),
85 @"iPad6,3" : @(RTCDeviceTypeIPadPro9Inch),
86 @"iPad6,4" : @(RTCDeviceTypeIPadPro9Inch),
87 @"iPad6,7" : @(RTCDeviceTypeIPadPro12Inch),
88 @"iPad6,8" : @(RTCDeviceTypeIPadPro12Inch),
89 @"iPad6,11" : @(RTCDeviceTypeIPad5),
90 @"iPad6,12" : @(RTCDeviceTypeIPad5),
91 @"iPad7,1" : @(RTCDeviceTypeIPadPro12Inch2),
92 @"iPad7,2" : @(RTCDeviceTypeIPadPro12Inch2),
93 @"iPad7,3" : @(RTCDeviceTypeIPadPro10Inch),
94 @"iPad7,4" : @(RTCDeviceTypeIPadPro10Inch),
95 @"iPad7,5" : @(RTCDeviceTypeIPad6),
96 @"iPad7,6" : @(RTCDeviceTypeIPad6),
97 @"i386" : @(RTCDeviceTypeSimulatori386),
98 @"x86_64" : @(RTCDeviceTypeSimulatorx86_64),
tkchind7629102016-07-28 14:52:55 -070099 };
100
tkchind7629102016-07-28 14:52:55 -0700101 RTCDeviceType deviceType = RTCDeviceTypeUnknown;
Kári Tristan Helgason0a1140e2017-10-05 13:18:14 +0200102 NSNumber *typeNumber = machineNameToType[[self machineName]];
tkchind7629102016-07-28 14:52:55 -0700103 if (typeNumber) {
104 deviceType = static_cast<RTCDeviceType>(typeNumber.integerValue);
105 }
106 return deviceType;
107}
108
Kári Tristan Helgason0a1140e2017-10-05 13:18:14 +0200109+ (NSString *)machineName {
110 struct utsname systemInfo;
111 uname(&systemInfo);
112 return [[NSString alloc] initWithCString:systemInfo.machine
113 encoding:NSUTF8StringEncoding];
tkchind7629102016-07-28 14:52:55 -0700114}
115
sdkdimon846e1be2017-03-06 16:42:19 -0800116+ (double)currentDeviceSystemVersion {
117 return [self currentDevice].systemVersion.doubleValue;
118}
119
JT Teha6368d12017-09-28 11:00:39 -0700120+ (BOOL)isIOS11OrLater {
121 return [self currentDeviceSystemVersion] >= 11.0;
122}
123
tkchind7629102016-07-28 14:52:55 -0700124@end