本文介绍了查找Mac OSX序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何查找Mac OSX序列号。
How to find the Mac OSX serial number.
有时需要获取一个mac的序列号,然后您就可以验证。
Sometimes it is required to get serial number of a mac, and you validate on that.
我需要相同的,几年前,当我开发了一个插件。我被要求释放它在这样的方式,只有很少的系统可以使用该插件。
I needed the same, few years back, when I developed a plugin for OsiriX. I was asked to release it in such a way, only few systems can use that plugin.
如果我们得到比这更好的解决方案,这将是对我们所有人非常有帮助。
推荐答案
以下代码主要从,
稍作修改以返回 NSString
并使用ARC编译:
The following code is mainly copied from Technical Note TN1103,with small modifications to return an NSString
and to make it compile with ARC:
#include <IOKit/IOKitLib.h>
- (NSString *)getSerialNumber
{
NSString *serial = nil;
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,
IOServiceMatching("IOPlatformExpertDevice"));
if (platformExpert) {
CFTypeRef serialNumberAsCFString =
IORegistryEntryCreateCFProperty(platformExpert,
CFSTR(kIOPlatformSerialNumberKey),
kCFAllocatorDefault, 0);
if (serialNumberAsCFString) {
serial = CFBridgingRelease(serialNumberAsCFString);
}
IOObjectRelease(platformExpert);
}
return serial;
}
您必须将IOKit.framework添加到构建设置中。
You have to add the IOKit.framework to your build settings.
这篇关于查找Mac OSX序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!