Skip to content

Commit 2d7070b

Browse files
Send userInterfaceIdiom to server instead of device model.
1 parent bd82d13 commit 2d7070b

File tree

1 file changed

+15
-45
lines changed

1 file changed

+15
-45
lines changed

swift-sdk/DeviceInfo.swift

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct DeviceInfo : Codable {
1818
}
1919

2020
struct DeviceFp : Codable {
21-
let iosDeviceType: String
21+
let userInterfaceIdiom: String
2222
let screenWidth: String
2323
let screenHeight: String
2424
let screenScale: String
@@ -39,7 +39,7 @@ struct DeviceInfo : Codable {
3939
// Therefore, the conversion from secondsFomGMT to timezoneOffsetMinutes is as follows.
4040
let secondsFromGMT = TimeZone.current.secondsFromGMT()
4141
let timezoneOffsetMinutes = (-1.0 * Float(secondsFromGMT) / 60.0)
42-
return DeviceFp(iosDeviceType: getModelName(),
42+
return DeviceFp(userInterfaceIdiom: getUserInterfaceIdiom(),
4343
screenWidth: String(Float(screen.bounds.width)),
4444
screenHeight: String(Float(screen.bounds.height)),
4545
screenScale: String(Float(screen.scale)),
@@ -48,49 +48,19 @@ struct DeviceInfo : Codable {
4848
language: Locale.current.identifier)
4949
}
5050

51-
private static func getModelName() -> String {
52-
var systemInfo = utsname()
53-
uname(&systemInfo)
54-
let machineMirror = Mirror(reflecting: systemInfo.machine)
55-
let identifier = machineMirror.children.reduce("") { identifier, element in
56-
guard let value = element.value as? Int8, value != 0 else { return identifier }
57-
return identifier + String(UnicodeScalar(UInt8(value)))
58-
}
59-
60-
switch identifier {
61-
case "iPod5,1": return "iPod Touch 5"
62-
case "iPod7,1": return "iPod Touch 6"
63-
case "iPhone3,1", "iPhone3,2", "iPhone3,3": return "iPhone 4"
64-
case "iPhone4,1": return "iPhone 4s"
65-
case "iPhone5,1", "iPhone5,2": return "iPhone 5"
66-
case "iPhone5,3", "iPhone5,4": return "iPhone 5c"
67-
case "iPhone6,1", "iPhone6,2": return "iPhone 5s"
68-
case "iPhone7,2": return "iPhone 6"
69-
case "iPhone7,1": return "iPhone 6 Plus"
70-
case "iPhone8,1": return "iPhone 6s"
71-
case "iPhone8,2": return "iPhone 6s Plus"
72-
case "iPhone9,1", "iPhone9,3": return "iPhone 7"
73-
case "iPhone9,2", "iPhone9,4": return "iPhone 7 Plus"
74-
case "iPhone8,4": return "iPhone SE"
75-
case "iPhone10,1", "iPhone10,4": return "iPhone 8"
76-
case "iPhone10,2", "iPhone10,5": return "iPhone 8 Plus"
77-
case "iPhone10,3", "iPhone10,6": return "iPhone X"
78-
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4":return "iPad 2"
79-
case "iPad3,1", "iPad3,2", "iPad3,3": return "iPad 3"
80-
case "iPad3,4", "iPad3,5", "iPad3,6": return "iPad 4"
81-
case "iPad4,1", "iPad4,2", "iPad4,3": return "iPad Air"
82-
case "iPad5,3", "iPad5,4": return "iPad Air 2"
83-
case "iPad2,5", "iPad2,6", "iPad2,7": return "iPad Mini"
84-
case "iPad4,4", "iPad4,5", "iPad4,6": return "iPad Mini 2"
85-
case "iPad4,7", "iPad4,8", "iPad4,9": return "iPad Mini 3"
86-
case "iPad5,1", "iPad5,2": return "iPad Mini 4"
87-
case "iPad6,3", "iPad6,4": return "iPad Pro 9.7 Inch"
88-
case "iPad6,7", "iPad6,8", "iPad7,1", "iPad7,2":return "iPad Pro 12.9 Inch"
89-
case "iPad7,3", "iPad7,4": return "iPad Pro 10.5 Inch"
90-
case "AppleTV5,3": return "Apple TV"
91-
case "AppleTV6,2": return "Apple TV 4K"
92-
case "i386", "x86_64": return "Simulator"
93-
default: return identifier
51+
/// Returns UserInterfaceIdiom as String to be passed to server
52+
private static func getUserInterfaceIdiom() -> String {
53+
switch UI_USER_INTERFACE_IDIOM() {
54+
case .phone:
55+
return "iPhone"
56+
case .pad:
57+
return "iPad"
58+
case .tv:
59+
return "AppleTV"
60+
case .carPlay:
61+
return "CarPlay"
62+
case .unspecified:
63+
return "Unknown"
9464
}
9565
}
9666
}

0 commit comments

Comments
 (0)