Skip to content

Commit 9d67448

Browse files
authored
Support Device Model (#21)
* Support Device Model Add device model information as part of environment info and system properties. * Check that uname returns 0
1 parent 42c2175 commit 9d67448

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

Sources/Aptabase/AptabaseClient.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class AptabaseClient {
3636
osVersion: env.osVersion,
3737
appVersion: env.appVersion,
3838
appBuildNumber: env.appBuildNumber,
39-
sdkVersion: AptabaseClient.sdkVersion
39+
sdkVersion: AptabaseClient.sdkVersion,
40+
deviceModel: env.deviceModel
4041
),
4142
props: props)
4243
dispatcher.enqueue(evt)

Sources/Aptabase/EnvironmentInfo.swift

+20-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct EnvironmentInfo {
1717
var locale = ""
1818
var appVersion = ""
1919
var appBuildNumber = ""
20+
var deviceModel = ""
2021

2122
static func current() -> EnvironmentInfo {
2223
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
@@ -28,7 +29,8 @@ struct EnvironmentInfo {
2829
osVersion: osVersion,
2930
locale: Locale.current.languageCode ?? "",
3031
appVersion: appVersion ?? "",
31-
appBuildNumber: appBuildNumber ?? ""
32+
appBuildNumber: appBuildNumber ?? "",
33+
deviceModel: deviceModel
3234
)
3335
}
3436

@@ -71,4 +73,21 @@ struct EnvironmentInfo {
7173
""
7274
#endif
7375
}
76+
77+
private static var deviceModel: String {
78+
if let simulatorModelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] {
79+
return simulatorModelIdentifier
80+
} else {
81+
var systemInfo = utsname()
82+
if uname(&systemInfo) == 0 {
83+
let identifier = withUnsafePointer(to: &systemInfo.machine) { ptr in
84+
ptr.withMemoryRebound(to: CChar.self, capacity: 1) { machinePtr in
85+
String(cString: machinePtr)
86+
}
87+
}
88+
return identifier
89+
}
90+
return ""
91+
}
92+
}
7493
}

Sources/Aptabase/EventDispatcher.swift

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct Event: Encodable {
1515
var appVersion: String
1616
var appBuildNumber: String
1717
var sdkVersion: String
18+
var deviceModel: String
1819
}
1920
}
2021

Tests/AptabaseTests/EventDispatcherTests.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ final class EventDispatcherTests: XCTestCase {
2121
isDebug: true,
2222
osName: "iOS",
2323
osVersion: "17.0",
24-
appVersion: "1.0.0"
24+
appVersion: "1.0.0",
25+
deviceModel: "iPhone16,2"
2526
)
2627

2728
override func setUp() {
@@ -90,7 +91,8 @@ final class EventDispatcherTests: XCTestCase {
9091
osVersion: env.osVersion,
9192
appVersion: env.appVersion,
9293
appBuildNumber: env.appBuildNumber,
93-
sdkVersion: "[email protected]")
94+
sdkVersion: "[email protected]",
95+
deviceModel: env.deviceModel)
9496
)
9597
}
9698
}

0 commit comments

Comments
 (0)