How to identify a Mac System uniquely

后端 未结 2 906
慢半拍i
慢半拍i 2021-02-01 10:05

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.

Kindl

2条回答
  •  天涯浪人
    2021-02-01 10:44

    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*.

提交回复
热议问题