Skip to content

Commit

Permalink
Merge pull request #22 from manucheri/20240429-fix-devicemodel-mac
Browse files Browse the repository at this point in the history
Fix device model identifier for Mac
  • Loading branch information
cristipufu authored Jun 8, 2024
2 parents 62e47da + 739bca7 commit 02f791e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sources/Aptabase/EnvironmentInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ struct EnvironmentInfo {
}

private static var deviceModel: String {
#if os(macOS) || targetEnvironment(macCatalyst)
// `uname` returns x86_64 (or Apple Silicon equivalent) for Macs.
// Use `sysctlbyname` here instead to get actual model name. If it fails, fall back to `uname`.
var size = 0
sysctlbyname("hw.model", nil, &size, nil, 0)
if size > 0 {
var model = [CChar](repeating: 0, count: size)
sysctlbyname("hw.model", &model, &size, nil, 0)
let deviceModel = String(cString: model)
// If we got a deviceModel, use it. Else continue to "default" logic.
if !deviceModel.isEmpty {
return deviceModel
}
}
#endif

if let simulatorModelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] {
return simulatorModelIdentifier
} else {
Expand Down

0 comments on commit 02f791e

Please sign in to comment.