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

问题描述 投票:0回答:1

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

cocoa udid deviceid
1个回答
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
}
© www.soinside.com 2019 - 2024. All rights reserved.