Mac OS X 开发对我来说是一个相当新的事物,我正在移植一些软件。对于软件许可和注册,我需要能够生成某种硬件 ID。它不必太花哨。以太网MAC地址、硬盘序列号、CPU序列号之类的。
我已经在 Windows 上覆盖了它,但在 Mac 上我一无所知。任何关于我需要做什么的想法,或者我可以去哪里获取这方面的信息都会很棒!
编辑:
对于其他对此感兴趣的人,这是我最终与 Qt 的 QProcess 类一起使用的代码:
QProcess proc;
QStringList args;
args << "-c" << "ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { print $3; }'";
proc.start( "/bin/bash", args );
proc.waitForFinished();
QString uID = proc.readAll();
注意:我使用的是 C++。
最佳答案
对于 C/C++:
#include <IOKit/IOKitLib.h>
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);
}
关于c++ - Mac OS X 中的唯一硬件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/933460/