2

How do I get device id in Apple Cocoa application with swift 4.2?

1 Answers1

6

You can get the Hardware UUID with IOKit

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
}
vadian
  • 274,689
  • 30
  • 353
  • 361