-
-
Save danielemaddaluno/179f73fef817338fd67ee5ad8ae206c5 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, kCFAllocatorDefault, 0) | |
| IOObjectRelease(platformExpert) | |
| let ser: CFTypeRef = serialNumberAsCFString.takeUnretainedValue() | |
| 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