mixpanel-swift icon indicating copy to clipboard operation
mixpanel-swift copied to clipboard

Model on macOS actually is actually the system architecture

Open mac-cain13 opened this issue 1 year ago • 2 comments

Currently the reported model on macOS is something like arm64 instead of a model identifier I expected. (Like MacBookPro18,1.)

I suspect this is a bug as iOS and macOS report different kind of values when querying the machine value. Also see the excellent blog on this at Cocoa with Love.

Therefore I would like to propose to change the behaviour by implementing specific logic for macOS to get the value for the model property instead of the architecture. This seems to be more useful and in line with what people might expect.

A reliable way to get the model on macOS is using IOKit:

// From: https://stackoverflow.com/a/50008492/586489
private func getModelIdentifier() -> String? {
    let service = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("IOPlatformExpertDevice"))
    var modelIdentifier: String?
    if let modelData = IORegistryEntryCreateCFProperty(service, "model" as CFString, kCFAllocatorDefault, 0).takeRetainedValue() as? Data {
        modelIdentifier = String(data: modelData, encoding: .utf8)?.trimmingCharacters(in: .controlCharacters)
    }
    IOObjectRelease(service)
    return modelIdentifier
}

Happy to create a Pull Request if this is indeed a change we want to maken and if it would help the maintainers.

mac-cain13 avatar Apr 05 '23 19:04 mac-cain13

@mac-cain13 Thanks for pointing this out. Yes, please feel free to make a PR and we will test it and get it merged.

jaredmixpanel avatar May 04 '23 18:05 jaredmixpanel

If this property is changed it would be great to still have the architecture available in another property, as I personally find it useful (despite the slightly confusing naming).

alexandersandberg avatar Aug 04 '23 22:08 alexandersandberg