From 945bddc7e1b3ab16731a19dbe21ffff206a46006 Mon Sep 17 00:00:00 2001 From: Brandon Sneed Date: Thu, 16 May 2024 11:59:49 -0700 Subject: [PATCH] Switched source for device model information on iOS (#350) * Make `shared()` public. * Switched source for device model info. --- .../Plugins/Platforms/Vendors/AppleUtils.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/Segment/Plugins/Platforms/Vendors/AppleUtils.swift b/Sources/Segment/Plugins/Platforms/Vendors/AppleUtils.swift index 0c5106a..75c0aa7 100644 --- a/Sources/Segment/Plugins/Platforms/Vendors/AppleUtils.swift +++ b/Sources/Segment/Plugins/Platforms/Vendors/AppleUtils.swift @@ -80,13 +80,14 @@ internal class iOSVendorSystem: VendorSystem { } private func deviceModel() -> String { - var name: [Int32] = [CTL_HW, HW_MACHINE] - var size: Int = 2 - sysctl(&name, 2, nil, &size, nil, 0) - var hw_machine = [CChar](repeating: 0, count: Int(size)) - sysctl(&name, 2, &hw_machine, &size, nil, 0) - let model = String(cString: hw_machine) - return model + var systemInfo = utsname() + uname(&systemInfo) + let machineMirror = Mirror(reflecting: systemInfo.machine) + let identifier = machineMirror.children.reduce("") { identifier, element in + guard let value = element.value as? Int8, value != 0 else { return identifier } + return identifier + String(UnicodeScalar(UInt8(value))) + } + return identifier } }