如何唯一识别Mac系统 [英] How to identify a Mac System uniquely

查看:136
本文介绍了如何唯一识别Mac系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过代码唯一地标识我的mac系统.我在关于本机"中找到了硬件UUID. 因此,如何通过编程方式从MAc OS X访问唯一的uuid.

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.

如果有其他建议可以解决我的问题,请提供我.

Kindly provide me if there are any alternative suggestion for my problem.

推荐答案

因此,如果您不关心新的AppStore规则等...,请继续:

So, if you don't care about the new AppStore rules etc... here you go:

- (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);;
}

请注意:

  • 为此,您需要将IOKit.framework添加到您的项目中 去工作.
  • 此代码符合ARC;
  • 此代码是安全的,如果出现问题,它将返回nil NSString
  • Apple不保证所有将来的系统都将具有软件可读的序列号.
  • 开发人员不应对 序列号的格式,例如长度或字符 可能包含.
  • You need to add IOKit.framework to your project in order for this to work.
  • This code is ARC compliant;
  • This code is safe and it will return a nil NSString if something goes wrong;
  • Apple does not guarantee that all future systems will have a software-readable serial number.
  • Developers should not make any assumptions about the format of the serial number such as its length or what characters it may contain.

这篇关于如何唯一识别Mac系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆