码迷,mamicode.com
首页 > 移动开发 > 详细

iOS获取机器SerialNumber

时间:2014-05-28 17:01:53      阅读:752      评论:0      收藏:0      [点我收藏+]

标签:style   c   a   color   int   get   

/**

 * 获取用户手机序列号

 */

+ (NSString *)serialNumber

{

    NSString *serialNumber = nil;

    

    void *IOKit = dlopen("/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_NOW);

    if (IOKit)

    {

        mach_port_t *kIOMasterPortDefault = dlsym(IOKit, "kIOMasterPortDefault");

        CFMutableDictionaryRef (*IOServiceMatching)(const char *name) = dlsym(IOKit, "IOServiceMatching");

        mach_port_t (*IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching) = dlsym(IOKit, "IOServiceGetMatchingService");

        CFTypeRef (*IORegistryEntryCreateCFProperty)(mach_port_t entry, CFStringRef key, CFAllocatorRef allocator, uint32_t options) = dlsym(IOKit, "IORegistryEntryCreateCFProperty");

        kern_return_t (*IOObjectRelease)(mach_port_t object) = dlsym(IOKit, "IOObjectRelease");

        

        if (kIOMasterPortDefault && IOServiceGetMatchingService && IORegistryEntryCreateCFProperty && IOObjectRelease)

        {

            mach_port_t platformExpertDevice = IOServiceGetMatchingService(*kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));

            if (platformExpertDevice)

            {

                CFTypeRef platformSerialNumber = IORegistryEntryCreateCFProperty(platformExpertDevice, CFSTR("IOPlatformSerialNumber"), kCFAllocatorDefault, 0);

                if (CFGetTypeID(platformSerialNumber) == CFStringGetTypeID())

                {

                    serialNumber = [NSString stringWithString:(__bridge NSString*)platformSerialNumber];

                    CFRelease(platformSerialNumber);

                }

                IOObjectRelease(platformExpertDevice);

            }

        }

        dlclose(IOKit);

    }

    

    return serialNumber;

}

iOS获取机器SerialNumber,布布扣,bubuko.com

iOS获取机器SerialNumber

标签:style   c   a   color   int   get   

原文地址:http://www.cnblogs.com/ZippoatiOS/p/3754980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!