Skip to content

Commit

Permalink
Support Device Model (#21)
Browse files Browse the repository at this point in the history
* Support Device Model

Add device model information as part of environment info and system
properties.

* Check that uname returns 0
  • Loading branch information
manucheri authored Mar 22, 2024
1 parent 42c2175 commit 9d67448
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Sources/Aptabase/AptabaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class AptabaseClient {
osVersion: env.osVersion,
appVersion: env.appVersion,
appBuildNumber: env.appBuildNumber,
sdkVersion: AptabaseClient.sdkVersion
sdkVersion: AptabaseClient.sdkVersion,
deviceModel: env.deviceModel
),
props: props)
dispatcher.enqueue(evt)
Expand Down
21 changes: 20 additions & 1 deletion Sources/Aptabase/EnvironmentInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct EnvironmentInfo {
var locale = ""
var appVersion = ""
var appBuildNumber = ""
var deviceModel = ""

static func current() -> EnvironmentInfo {
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
Expand All @@ -28,7 +29,8 @@ struct EnvironmentInfo {
osVersion: osVersion,
locale: Locale.current.languageCode ?? "",
appVersion: appVersion ?? "",
appBuildNumber: appBuildNumber ?? ""
appBuildNumber: appBuildNumber ?? "",
deviceModel: deviceModel
)
}

Expand Down Expand Up @@ -71,4 +73,21 @@ struct EnvironmentInfo {
""
#endif
}

private static var deviceModel: String {
if let simulatorModelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] {
return simulatorModelIdentifier
} else {
var systemInfo = utsname()
if uname(&systemInfo) == 0 {
let identifier = withUnsafePointer(to: &systemInfo.machine) { ptr in
ptr.withMemoryRebound(to: CChar.self, capacity: 1) { machinePtr in
String(cString: machinePtr)
}
}
return identifier
}
return ""
}
}
}
1 change: 1 addition & 0 deletions Sources/Aptabase/EventDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct Event: Encodable {
var appVersion: String
var appBuildNumber: String
var sdkVersion: String
var deviceModel: String
}
}

Expand Down
6 changes: 4 additions & 2 deletions Tests/AptabaseTests/EventDispatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ final class EventDispatcherTests: XCTestCase {
isDebug: true,
osName: "iOS",
osVersion: "17.0",
appVersion: "1.0.0"
appVersion: "1.0.0",
deviceModel: "iPhone16,2"
)

override func setUp() {
Expand Down Expand Up @@ -90,7 +91,8 @@ final class EventDispatcherTests: XCTestCase {
osVersion: env.osVersion,
appVersion: env.appVersion,
appBuildNumber: env.appBuildNumber,
sdkVersion: "[email protected]")
sdkVersion: "[email protected]",
deviceModel: env.deviceModel)
)
}
}

0 comments on commit 9d67448

Please sign in to comment.