如何生成应该适用于所有iOS版本的唯一标识符? [英] How to generate unique identifier which should work in all iOS versions?

查看:204
本文介绍了如何生成应该适用于所有iOS版本的唯一标识符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得应该支持所有iOS版本的唯一标识符。任何人都可以帮助我解决这个问题。如你所知,苹果不推荐使用UDID方法,因此有可能使用wifi-mac地址生成唯一ID。但苹果将删除iOS7版本中的wifi mac地址。所以我的要求是生成一个新的唯一代码应该适用于所有iOS版本。提前谢谢..



注意:用户重启设备或重新安装应用程序后,请勿更改UDID。

解决方案

我正在更新我的应用程序,该应用程序仅基于支持 iOS 4.3及更高版本的唯一标识符工作。所以,



1)我无法使用 [UIDevice currentDevice] .uniqueIdentifier; 因为它不再可用



2)我无法使用 [UIDevice currentDevice] .identifierForVendor.UUIDString 因为它仅在iOS 6.0及更高版本中可用且无法用于较低的iOS版本。



3)mac地址不是一个选项,因为它不被允许在iOS-7中



4)


I want to get the unique identifier which should support all iOS versions..Can any one help me on this issue. As you know that apple is deprecated the UDID method, So there is possibility to generate Unique id using wifi-mac address.But apple is going to remove the wifi mac address in iOS7 version.So my requirement is to generate a new unique code which should work in all iOS versions.Thanks in advance..

Note: Don't change the UDID once user restart the device or reinstall the application.

解决方案

I was updating my application that was working based only on Unique Identifier which supported iOS 4.3 and above. So,

1) I was unable to use [UIDevice currentDevice].uniqueIdentifier; as it was no longer available

2) I could not use [UIDevice currentDevice].identifierForVendor.UUIDString because it was Available in iOS 6.0 and later only and was unable to use for lower iOS versions.

3) The mac address was not an option as it wasn't allowed in iOS-7

4) OpenUDID was deprecated some time ago and also had issues with iOS-6.

5) Advertisement identifiers were also not available for iOS-5 and below

Finally this was what i did

a) Added SFHFKeychainUtils to the project

b) Generated CFUUID key String

 CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
    udidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));

c) Saved it to Key Chain Utils or else it will generate a new Unique Each Time

Final Code

+ (NSString *)GetDeviceID {
    NSString *udidString;
   udidString = [self objectForKey:@"deviceID"];
    if(!udidString)
    {
    CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
    udidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));
    CFRelease(cfuuid);
        [self setObject:udidString forKey:@"deviceID"];
    }
    return udidString;
}

+(void) setObject:(NSString*) object forKey:(NSString*) key
{
    NSString *objectString = object;
    NSError *error = nil;
    [SFHFKeychainUtils storeUsername:key
                         andPassword:objectString
                      forServiceName:@"LIB"
                      updateExisting:YES
                               error:&error];

    if(error)
        NSLog(@"%@", [error localizedDescription]);
}

+(NSString*) objectForKey:(NSString*) key
{
    NSError *error = nil;
    NSString *object = [SFHFKeychainUtils getPasswordForUsername:key
                                                  andServiceName:@"LIB"
                                                           error:&error];
    if(error)
        NSLog(@"%@", [error localizedDescription]);

    return object;
}

For further Details

这篇关于如何生成应该适用于所有iOS版本的唯一标识符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆