zoukankan      html  css  js  c++  java
  • 获得设备的唯一标识符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

  • 相关阅读:
    Google的Java常用类库 Guava资料
    Java 理论与实践: 哈希
    7 款开源 Java 反编译工具
    Eclipse传递main函数参数
    Java程序员常用工具类库
    Eclipse 安装插件
    学习Javascript的8张思维导图
    java开发者最常去的20个英文网站
    关于工作效率的心得分享
    ProtoBuf开发者指南
  • 原文地址:https://www.cnblogs.com/liyy2015/p/6090204.html
Copyright © 2011-2022 走看看