獲得設備的唯一標識符UDID


在IOS5之后,蘋果為避免根據UDID獲得用戶的信息,而禁止使用uniqueIdentifier獲得UDID,但是仍有些應用需要根據UDID區分設備

有一個系統的庫IOKit.framework可以獲得設備的唯一標識

    NSString *serialNumber = nil;

    NSString * path = [[NSBundle mainBundle]pathForResource:@"IOKit.framework" ofType:nil];

    const char * a =[path UTF8String];

//    void *IOKit = dlopen(a, RTLD_NOW);

    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("IOPlatformUUID"), kCFAllocatorDefault, 0);

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

                {

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

                    CFRelease(platformSerialNumber);

                }

                IOObjectRelease(platformExpertDevice);

            }

        }

        dlclose(IOKit);

    }

    return serialNumber;

但是這個方法只能獲得模擬器上的UDID很坑爹啊

那還有另外的方法獲得設備的信息,那就是走蘋果的MDM

詳情參考http://www.cnblogs.com/liyy2015/p/6030032.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM