Kak*_*key 8 macos objective-c hardware-id
我想通过代码唯一地识别我的mac系统.我在关于这台Mac上找到了硬件UUID.那么如何以编程方式从MAc OS X访问唯一的uuid.
如果对我的问题有任何其他建议,请提供给我.
TCB*_*B13 19
所以,如果您不关心新的AppStore规则等......请转到:
- (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);;
}
Run Code Online (Sandbox Code Playgroud)
请注意:
IOKit.framework到项目中才能使其正常工作.nil NSString如果出现问题它将返回;从这里: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);
}
Run Code Online (Sandbox Code Playgroud)
您可以通过简单转换为 NSString* 来替换 CFStringGetCString。
| 归档时间: |
|
| 查看次数: |
5616 次 |
| 最近记录: |