Last active
February 6, 2019 09:26
-
-
Save eryshkov/7ddcb89e00a2dc00a951426c80a99133 to your computer and use it in GitHub Desktop.
[UUID and Serial for mac]
This file contains 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
//: Playground - noun: a place where people can play | |
import Cocoa | |
func getSerial() -> String? {//Получить серийный номер mac-компьютера | |
let platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice") ) | |
guard platformExpert > 0 else { | |
return nil | |
} | |
guard let serialNumber = (IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformSerialNumberKey as CFString, kCFAllocatorDefault, 0).takeUnretainedValue() as? String)?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) else { | |
return nil | |
} | |
IOObjectRelease(platformExpert) | |
return serialNumber | |
} | |
func getSystemUUID() -> String? {//Получить SystemUUID для устройства Apple | |
let dev = IOServiceMatching("IOPlatformExpertDevice") | |
let platformExpert: io_service_t = IOServiceGetMatchingService(kIOMasterPortDefault, dev) | |
let serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformUUIDKey as CFString, kCFAllocatorDefault, 0) | |
IOObjectRelease(platformExpert) | |
let ser: CFTypeRef = serialNumberAsCFString!.takeUnretainedValue() | |
if let result = ser as? String { | |
return result | |
} | |
return nil | |
} | |
print("your mac serial is \(getSerial() ?? "not found")") | |
print("Your system UUID is \(getSystemUUID() ?? "not found")") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's working fine. Thank you !