Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify a Mac System uniquely

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.

like image 274
Kakey Avatar asked Jun 20 '12 06:06

Kakey


1 Answers

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:

  • You need to add IOKit.framework to your project in order for this to work.
  • This code is ARC compliant;
  • This code is safe and it will return a nil NSString if something goes wrong;
  • Apple does not guarantee that all future systems will have a software-readable serial number.
  • Developers should not make any assumptions about the format of the serial number such as its length or what characters it may contain.
like image 50
TCB13 Avatar answered Oct 03 '22 20:10

TCB13