mirror of
https://github.com/aptabase/aptabase-swift.git
synced 2026-01-18 22:21:17 +01:00
Fix device model for Mac
`uname` returns x86_64 (or Apple Silicon equivalent) for Macs. Get the device name in another way for Mac devices. If it fails, fallback to the default way (can be represented as "unknown Mac" or similar).
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user