I want to identify my mac system uniquely via code. I find the Hardware UUID in my About this Mac. So how to programmatically access the unique uuid from MAc OS X.
Kindly provide me if there are any alternative suggestion for my problem.
I want to identify my mac system uniquely via code. I find the Hardware UUID in my About this Mac. So how to programmatically access the unique uuid from MAc OS X.
Kindly provide me if there are any alternative suggestion for my problem.
So, if you don't care about the new AppStore rules etc... here you go:
- (NSString *)getSystemUUID {
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,IOServiceMatching("IOPlatformExpertDevice"));
if (!platformExpert)
return nil;
CFTypeRef serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert,CFSTR(kIOPlatformUUIDKey),kCFAllocatorDefault, 0);
IOObjectRelease(platformExpert);
if (!serialNumberAsCFString)
return nil;
return (__bridge NSString *)(serialNumberAsCFString);;
}
Please Note:
IOKit.framework
to your project in order for this
to work. nil
NSString
if something goes wrong;From here: https://stackoverflow.com/a/2754563/610351
void get_platform_uuid(char * buf, int bufSize) {
io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
IOObjectRelease(ioRegistryRoot);
CFStringGetCString(uuidCf, buf, bufSize, kCFStringEncodingMacRoman);
CFRelease(uuidCf);
}
You can replace the CFStringGetCString with a simple conversion to NSString*.