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

时间:2019-03-05 11:18:24

标签: cocoa udid deviceid

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

1 个答案:

答案 0 :(得分:1)

您可以通过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
}