Method [[UIDevice currentDevice] uniqueIdentifier] is not allowed any more, I need an alternative

后端 未结 3 1911
执笔经年
执笔经年 2020-12-31 19:10

I\'m using [[UIDevice currentDevice] uniqueIdentifier] in all of my apps, Apple is not allowing the use of uniqueIdentifier anymore. I need somethi

3条回答
  •  失恋的感觉
    2020-12-31 19:41

    Update for iOS 7 and prior:

    + (NSString *)uniqueDeviceIdentifier
    {
        NSString *device_id = nil;
    
        if ([[self deviceModel] isEqualToString:@"Simulator iOS"]) {
            // static id for simulator
            device_id = @"== your random id ==";
        }
        else if (CurrentIOSVersion >= 6.f) {
            // iOS 6 and later
            device_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        }
        else {
            // iOS 5 and prior
            SEL udidSelector = NSSelectorFromString(@"uniqueIdentifier");
            if ([[UIDevice currentDevice] respondsToSelector:udidSelector]) {
                device_id = [[UIDevice currentDevice] performSelector:udidSelector];
            }
        }
        NSLog(@">>>>>> device_id: %@", device_id);
        return device_id;
    }
    

    Device model you can receive through:

    + (NSString*)deviceModel
    {
        static NSString *device_model = nil;
    
        if (device_model != nil)
            return device_model;
    
        struct utsname systemInfo;
        uname(&systemInfo);
        NSString *str = @(systemInfo.machine);
    
        return device_model;
    }
    

提交回复
热议问题