-
-
Save donly/072d8e6beabaf4421c0248a34ddb7c29 to your computer and use it in GitHub Desktop.
Swift: get the Mac UUID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getSystemUUID() -> String? { | |
let dev = IOServiceMatching("IOPlatformExpertDevice") | |
let platformExpert: io_service_t = IOServiceGetMatchingService(kIOMasterPortDefault, dev) | |
let serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformUUIDKey as CFString, kCFAllocatorDefault, 0) | |
IOObjectRelease(platformExpert) | |
guard let ser: CFTypeRef = serialNumberAsCFString?.takeUnretainedValue() else { return nil } | |
if let result = ser as? String { | |
return result | |
} | |
return nil | |
} | |
if let uuid = getSystemUUID() { | |
print(uuid) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment