Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model on macOS actually is actually the system architecture #597

Open
mac-cain13 opened this issue Apr 5, 2023 · 2 comments
Open

Model on macOS actually is actually the system architecture #597

mac-cain13 opened this issue Apr 5, 2023 · 2 comments

Comments

@mac-cain13
Copy link

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 mac-cain13 changed the title Model on macOS actually is system architecture Model on macOS actually is actually the system architecture Apr 5, 2023
@jaredmixpanel
Copy link
Contributor

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

@alexandersandberg
Copy link
Contributor

alexandersandberg commented Aug 4, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants