blob: 96adb9af780e13f09882ead7d848aee7c616c090 [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 = @{
20 @"iPhone1,1": @(RTCDeviceTypeIPhone1G),
21 @"iPhone1,2": @(RTCDeviceTypeIPhone3G),
22 @"iPhone2,1": @(RTCDeviceTypeIPhone3GS),
23 @"iPhone3,1": @(RTCDeviceTypeIPhone4),
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030024 @"iPhone3,2": @(RTCDeviceTypeIPhone4),
tkchind7629102016-07-28 14:52:55 -070025 @"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 Yaroshevich0f77fea2018-04-26 15:41:01 +030037 @"iPhone8,4": @(RTCDeviceTypeIPhoneSE),
Kári Tristan Helgason0a1140e2017-10-05 13:18:14 +020038 @"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),
tkchind7629102016-07-28 14:52:55 -070048 @"iPod1,1": @(RTCDeviceTypeIPodTouch1G),
49 @"iPod2,1": @(RTCDeviceTypeIPodTouch2G),
50 @"iPod3,1": @(RTCDeviceTypeIPodTouch3G),
51 @"iPod4,1": @(RTCDeviceTypeIPodTouch4G),
52 @"iPod5,1": @(RTCDeviceTypeIPodTouch5G),
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030053 @"iPod7,1": @(RTCDeviceTypeIPodTouch6G),
tkchind7629102016-07-28 14:52:55 -070054 @"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 Yaroshevich0f77fea2018-04-26 15:41:01 +030070 @"iPad4,3": @(RTCDeviceTypeIPadAirWifiCellular),
tkchind7629102016-07-28 14:52:55 -070071 @"iPad4,4": @(RTCDeviceTypeIPadMini2GWifi),
72 @"iPad4,5": @(RTCDeviceTypeIPadMini2GCellular),
Yura Yaroshevich0f77fea2018-04-26 15:41:01 +030073 @"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),
tkchind7629102016-07-28 14:52:55 -070093 @"i386": @(RTCDeviceTypeSimulatori386),
94 @"x86_64": @(RTCDeviceTypeSimulatorx86_64),
95 };
96
tkchind7629102016-07-28 14:52:55 -070097 RTCDeviceType deviceType = RTCDeviceTypeUnknown;
Kári Tristan Helgason0a1140e2017-10-05 13:18:14 +020098 NSNumber *typeNumber = machineNameToType[[self machineName]];
tkchind7629102016-07-28 14:52:55 -070099 if (typeNumber) {
100 deviceType = static_cast<RTCDeviceType>(typeNumber.integerValue);
101 }
102 return deviceType;
103}
104
Kári Tristan Helgason0a1140e2017-10-05 13:18:14 +0200105+ (NSString *)machineName {
106 struct utsname systemInfo;
107 uname(&systemInfo);
108 return [[NSString alloc] initWithCString:systemInfo.machine
109 encoding:NSUTF8StringEncoding];
tkchind7629102016-07-28 14:52:55 -0700110}
111
sdkdimon846e1be2017-03-06 16:42:19 -0800112+ (double)currentDeviceSystemVersion {
113 return [self currentDevice].systemVersion.doubleValue;
114}
115
JT Teha6368d12017-09-28 11:00:39 -0700116+ (BOOL)isIOS11OrLater {
117 return [self currentDeviceSystemVersion] >= 11.0;
118}
119
tkchind7629102016-07-28 14:52:55 -0700120@end