Are there new device identifiers in iOS 10?

放肆的年华 提交于 2019-12-02 01:08:13

问题


Has anyone found a new way to uniquely identify a device in iOS 10? I haven't seen any documentation mentioning changes in that area and I wanted to ask before I surrendered to identifier for vendor.


回答1:


If you're submitting to the store, the only real identifier you have left is the Advertising Identifier for the AdSupport framework.

If you want to go down the rabbit hole a little further and potentially go into some unsafe API territory, you could hook into IOKit and try to get the battery identifier on the device. This is taken from Anthony Agatiello gist of UIDevice extensions:

- (NSString *)batteryID {
    void *IOKit = dlopen("/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit", RTLD_LAZY);
    NSParameterAssert(IOKit);

    mach_port_t *kIOMasterPortDefault = dlsym(IOKit, "kIOMasterPortDefault");
    NSParameterAssert(kIOMasterPortDefault);
    CFMutableDictionaryRef (*IOServiceNameMatching)(const char *name) = dlsym(IOKit, "IOServiceNameMatching");
    NSParameterAssert(IOServiceNameMatching);
    mach_port_t (*IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching) = dlsym(IOKit, "IOServiceGetMatchingService");
    NSParameterAssert(IOServiceGetMatchingService);
    kern_return_t (*IORegistryEntryCreateCFProperties)(mach_port_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, UInt32 options) = dlsym(IOKit, "IORegistryEntryCreateCFProperties");
    NSParameterAssert(IORegistryEntryCreateCFProperties);
    kern_return_t (*IOObjectRelease)(mach_port_t object) = dlsym(IOKit, "IOObjectRelease");
    NSParameterAssert(IOObjectRelease);

    CFMutableDictionaryRef properties = NULL;

    mach_port_t service = IOServiceGetMatchingService(*kIOMasterPortDefault, IOServiceNameMatching("charger"));
    IORegistryEntryCreateCFProperties(service, &properties, kCFAllocatorDefault, 0);

    IOObjectRelease(service);
    service = 0;

    NSDictionary *dictionary = (__bridge NSDictionary *)properties;
    NSData *batteryIDData = [dictionary objectForKey:@"battery-id"];

    CFRelease(properties);
    properties = NULL;

    dlclose(IOKit);

    return [NSString stringWithUTF8String:[batteryIDData bytes]];
}

This still works on iOS 10.



来源:https://stackoverflow.com/questions/38101380/are-there-new-device-identifiers-in-ios-10

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!