I want unique identifier string which detect iPhone device (just like UDID)?
Asked Answered
A

5

19

I want unique identifier string for iPhone devices instead of UDID and MAC.

1. Get UDID and MAC are deprecated by apple.
2. We can use UUID but it will get change after reinstalling app or delete app.

I want any unique value of device which is remain same after app reinstall OR delete OR upgrade iOS version.

Appellee answered 21/5, 2013 at 7:2 Comment(4)
Can you show me documentation where the MAC address is deprecated? I hadn't heard this one.Sexy
I think your only option is to query MAC address and do something with it.. It is already discussed here, and so I think this question is a duplicate. And I don't think MAC address is deprecated, atleast I can't find any documentationLunge
If your iOS target is 6.0 and above there is the [[UIDevice currentDevice] identifierForVendor];Classic
UDID has been deprecated but this is the first time I have heard the MAC address has been deprecated. Please could you share this documentation that you have read this in so we can be up to date. Also check out my answer on here #7129328Philately
T
21

What you can do is get a unique identifier using [[UIDevice currentDevice] identifierForVendor]or any other unique identifier generator. After that, you should store that value on keychain using KeychainItemWrapper and use. Once you store a value on the keychain it'll not remove even after you delete and reinstall the app.

Here is a guide for keychain access - Link

Tanbark answered 21/5, 2013 at 8:41 Comment(2)
Thanks for the keychain add. I didn't know about that. I'll implement that also in my solution.Pavlodar
But what if user restore his/her phone? at that time keychain also removed.Duodenary
P
2

As @danypata said, use the identifierForVendor as described in this answer.

Or alternatively you might be able to use the advertising NSUDID as described here.

However these can come back as nil or be changed over time. The user can opt out of advertiser tracking, so I don't recommend using it to track users for your own purposes.

I guess it depends on why you are tracking their device in the first place. My attitude is that I don't need to track users habits FOREVER. I only need to track general user trends and some DAU info. So I make up my own UDID - which will change on each install of the app. In my next version I will use the identifierForVendor and if it's NIL I will make up my own.

This is how I make my own:

// this makes a device id like: UUID = 89CD872F-C9AF-4518-9E6C-A01D35AF091C
// except that I'm going to attach some other attributes to it like the OS version, model type, etc.
// the UUID that is stored in user defaults will be like the one above.. but the device id that gets returned
// from this function and sent to [my online system] will have the extra info at the end of the string.
- (void) createUUID {
   // for collecting some data.. let's add some info about the device to the uuid

   NSString *thisDeviceID;
   NSString *systemVersion = [[UIDevice currentDevice]systemVersion];
   NSString *model = [[UIDevice currentDevice]model];
   NSString *retinaTag;
   if (retina) {
       retinaTag = @"Retina";
   }
   else {
       retinaTag = @"";
   }
   NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
   id uuid = [defaults objectForKey:@"uniqueID"];
   if (uuid)
       thisDeviceID = (NSString *)uuid;
   else {
       CFStringRef cfUuid = CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
       thisDeviceID = (__bridge NSString *)cfUuid;
       CFRelease(cfUuid);
       [defaults setObject:thisDeviceID forKey:@"uniqueID"];
   }
   //NSLog(@"UUID = %@", thisDeviceID);

   MYthisDeviceID = [NSString stringWithFormat:@"%@-%@-%@-%@",thisDeviceID,systemVersion,retinaTag,model];

   //NSLog(@"UUID with info = %@", MYthisDeviceID);

}

Then the single string that gets sent to my server has both a UDID in it and specs about the device and os. Until the user completely deletes and reloads the app the stats show usage on that device. To not get double udids if they update to a new os you can crop to just the udid portion.

I don't use the mac address at all because it was my understanding that apple didn't want us to. Although I can't find any documentation that says it at the moment.

UPDATE for iOS7:

I now use this code which works under io6 and io7:

NSString *globalDeviceID;

- (void) createUUID
{
    NSString *thisDeviceID;
    NSString *systemVersion = [[UIDevice currentDevice]systemVersion];
    NSString *model = [[UIDevice currentDevice]model];
    NSString *retinaTag;

    if (retina) {
        retinaTag = @"Retina";
    }
    else {
        retinaTag = @"";
    }

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    id uuid = [defaults objectForKey:@"deviceID"];
    if (uuid)
        thisDeviceID = (NSString *)uuid;
    else {        
        if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
            thisDeviceID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        }
        else
        {
            CFStringRef cfUuid = CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
            thisDeviceID = (__bridge NSString *)cfUuid;
            CFRelease(cfUuid);
        }
        [defaults setObject:thisDeviceID forKey:@"deviceID"];
    }
    NSLog(@"UUID = %@", thisDeviceID);
    globalDeviceID = [NSString stringWithFormat:@"%@-%@-%@-%@",thisDeviceID,systemVersion,retinaTag,model];
    NSLog(@"UUID with info = %@", globalDeviceID);
}
Pavlodar answered 21/5, 2013 at 7:36 Comment(3)
Hi, Isn't this code crashing with iOS 7 ?? I have implemented a bit different form of this code and it started crashing in iOS7Avril
I'll edit my answer to add my current version of this code, which I use in io7 just fine.Pavlodar
The only problem with advertising NSUDID that Apple will ask about the usage during review, so maybe it could mean a different review or anything else which may be better to avoid...never know...Rosettarosette
D
2

Try

[[UIDevice currentDevice] identifierForVendor];

It is from iOS 6.

Darlenadarlene answered 21/5, 2013 at 8:28 Comment(1)
but I don,t knoe can i take UDID for older version of ios6Appellee
P
2

Or simply use the following and store to NSUserDefaults

[NSProcessInfo processInfo].globallyUniqueString

Global ID for the process. The ID includes the host name, process ID, and a time stamp, which ensures that the ID is unique for the network.

Potash answered 12/11, 2013 at 20:55 Comment(0)
S
0

I'd suggest having a look at OpenUDID.

I believe underneath it uses the MAC address, so if you are correct in saying that accessing the MAC address is deprecated, then it probably won't be of much use, however, I think it would be unreasonable of Apple to remove access; the MAC address has other applications that just identifying the device for the purposes of UDID

Sexy answered 21/5, 2013 at 7:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.