TelemetryDeck / SwiftSDK

Swift SDK for TelemetryDeck, a privacy-conscious analytics service for apps and websites.
https://telemetrydeck.com/
Other
155 stars 32 forks source link

Return correct model name on macOS #60

Closed winsmith closed 2 years ago

winsmith commented 2 years ago

Right now we only return the model name when running the Swift SDK in macOS. Instead, it should return the hardware identifier.

Using IOKit:

public func getMacModel() -> String? {
    let service = IOServiceGetMatchingService(kIOMasterPortDefault,
                                              IOServiceMatching("IOPlatformExpertDevice"))
    var modelIdentifier: String?

    if let modelData = IORegistryEntryCreateCFProperty(service, "model" as CFString, kCFAllocatorDefault, 0).takeRetainedValue() as? Data {
        if let modelIdentifierCString = String(data: modelData, encoding: .utf8)?.cString(using: .utf8) {
            modelIdentifier = String(cString: modelIdentifierCString)
        }
    }

    IOObjectRelease(service)
    return modelIdentifier
}

This will have to be gated with "if OS macOS" calls, so that the SDK still compiles for iOS and Linux.

tonyarnold commented 2 years ago

Did this make it into 7.23.0?

winsmith commented 2 years ago

Sorry I don't have write access to sentry :D~

This is not in 1.1.6 but I'll add it to the upcoming 1.2 :)

tonyarnold commented 2 years ago

OMFG… it has been one of those days. Sorry!