Mac获取系统序列号的方法

char serialNumber[256];
if (serialNumber != NULL) 
{
	io_service_t    platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,IOServiceMatching("IOPlatformExpertDevice"));
	if (platformExpert) 
	{
		CFTypeRef serialNumberCF =  IORegistryEntryCreateCFProperty(platformExpert,CFSTR(kIOPlatformSerialNumberKey),kCFAllocatorDefault,0);
		IOObjectRelease(platformExpert);
		if(serialNumber) 
		{
			if(CFGetTypeID(serialNumberCF)==CFDataGetTypeID())
			{
				CFRange cfrange = CFRangeMake(0,CFDataGetLength((CFDataRef)serialNumberCF));
				CFDataGetBytes((CFDataRef)serialNumberCF,cfrange,(UInt8*)serialNumber);
			}
			else if(CFGetTypeID(serialNumberCF)==CFStringGetTypeID())
			{
				CFStringGetCString((CFStringRef)serialNumberCF, serialNumber,256, kCFStringEncodingUTF8);
			}
			CFRelease(serialNumberCF);
		}
	}
}
Mac获取系统序列号的方法_第1张图片

你可能感兴趣的:(Mac,OSX开发)