Skip to content

Commit 945bddc

Browse files
authored
Switched source for device model information on iOS (#350)
* Make `shared()` public. * Switched source for device model info.
1 parent 44cab1e commit 945bddc

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Sources/Segment/Plugins/Platforms/Vendors/AppleUtils.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ internal class iOSVendorSystem: VendorSystem {
8080
}
8181

8282
private func deviceModel() -> String {
83-
var name: [Int32] = [CTL_HW, HW_MACHINE]
84-
var size: Int = 2
85-
sysctl(&name, 2, nil, &size, nil, 0)
86-
var hw_machine = [CChar](repeating: 0, count: Int(size))
87-
sysctl(&name, 2, &hw_machine, &size, nil, 0)
88-
let model = String(cString: hw_machine)
89-
return model
83+
var systemInfo = utsname()
84+
uname(&systemInfo)
85+
let machineMirror = Mirror(reflecting: systemInfo.machine)
86+
let identifier = machineMirror.children.reduce("") { identifier, element in
87+
guard let value = element.value as? Int8, value != 0 else { return identifier }
88+
return identifier + String(UnicodeScalar(UInt8(value)))
89+
}
90+
return identifier
9091
}
9192
}
9293

0 commit comments

Comments
 (0)