如何在 Apple Cocoa 应用程序中获取设备 ID?

How do I get device id in the Apple Cocoa application?

如何使用 swift 4.2 在 Apple Cocoa 应用程序中获取设备 ID?

您可以使用 IOKit

获取 硬件 UUID
func hardwareUUID() -> String?
{
    let matchingDict = IOServiceMatching("IOPlatformExpertDevice")
    let platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict)
    defer{ IOObjectRelease(platformExpert) }

    guard platformExpert != 0 else { return nil }
    return IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformUUIDKey as CFString, kCFAllocatorDefault, 0).takeRetainedValue() as? String
}