Obtain the unique identifier (UDID) of the device.

Source: Internet
Author: User

Obtain the unique identifier (UDID) of the device.

After IOS5, to avoid obtaining user information based on UDID, Apple prohibits the use of uniqueIdentifier to obtain UDID. However, some applications still need to differentiate devices based on UDID.

There is a system library IOKit. framework that can obtain the unique identifier of the device.

    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;

However, this method can only obtain the UDID on the simulator.

There is another way to get device information, that is, using Apple's MDM

Reference http://www.cnblogs.com/liyy2015/p/6030032.html for details

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.