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

如何在Apple Cocoa应用程序中获取设备id?,cocoa,udid,deviceid,Cocoa,Udid,Deviceid,如何使用swift 4.2在Apple Cocoa应用程序中获取设备id?您可以使用IOKit获取硬件UUID func hardwareUUID() -> String? { let matchingDict = IOServiceMatching("IOPlatformExpertDevice") let platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict)

如何使用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
}
您可以使用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
}

设备id对于macOS意味着什么?每个设备的唯一字符串id也可以获取UIDevice.current.identifierForVendor。uuistring,但这在MacOS中不会发生。我可以为MacOS应用程序做什么设备id对于MacOS意味着什么?每个设备的唯一字符串id也可以获取UIDevice.current.identifierForVendor。uuistring,但这在MacOS中不会发生。我能为MacOS应用程序做些什么