what is the replica for UDID or UUID in iOS 7

匆匆过客 提交于 2019-12-24 13:42:18

问题


Problem is once I am generating UUID its working for me. But if me/user delete the application than UUID is not same like i have generated before. There is no uniqueness here if we are using uuid as identifier. Please help me to solve this issue.How can i get same uuid or any string if application reinstalled. Thanks in advance..

I am using this approach:

NSString *udid;

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
    udid = [UIDevice currentDevice].identifierForVendor.UUIDString;
else
    udid = [UIDevice currentDevice].uniqueIdentifier;

回答1:


First, check this very informative post on NSHiplster http://nshipster.com/uuid-udid-unique-identifier/

This should be working for you:

NSString *UUIDString = nil;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
    UUIDString = [[NSUUID UUID] UUIDString];
} else {
    CFUUIDRef UUID = CFUUIDCreate(NULL);
    UUIDString = CFBridgingRelease(CFUUIDCreateString(NULL, UUID));
}



回答2:


I have solved this by using advertisingIdentifier. Link:

https://developer.apple.com/library/ios/documentation/AdSupport/Reference/ASIdentifierManager_Ref/ASIdentifierManager.html#jumpTo_3

As I have seen there that advertisingIdentifier is

"An alphanumeric string unique to each device, ..."

For that I have used it as the unique identifier (though it is used for the serving advertisements).

My code is:

-(NSString*)UniqueAppId
{
    NSString *Appname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
    NSString *strApplicationUUID = [SSKeychain passwordForService:Appname account:@"manab"];
    if (strApplicationUUID == nil)
    {
        strApplicationUUID  = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
        [SSKeychain setPassword:strApplicationUUID forService:Appname account:@"manab"];
    }
    return strApplicationUUID;
}

and just calling it when needed as

[self UniqueAppId];


来源:https://stackoverflow.com/questions/19675805/what-is-the-replica-for-udid-or-uuid-in-ios-7

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