1

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

4

1 回答 1

5

您可以使用 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
}
于 2019-03-05T11:31:11.980 回答