Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CFUUIDCreate UUID changes constantly

Tags:

uuid

ios

I am a beginner iPhone app developer and I am trying to show the iPhone or App unique identifier on a label through an IBAction button. I researched a little and know that some of the code have been deprecated and CFUUID is used instead. The code below is what I used. However, every time I touch the IBAction button, the UUID changes. What am I doing wrong?

CFUUIDRef udid = CFUUIDCreate(NULL);

NSString *udidString = (NSString *) CFUUIDCreateString(NULL, udid);

uuid.text= udidString;  
like image 794
wakaka Avatar asked Mar 21 '12 09:03

wakaka


Video Answer


2 Answers

I think you have misunderstood the purpose of CFUUIDCreate(), Read its documentation you'll understand.

I guess the API is serving it's purpose properly, which is to create universally unique identifier means every time you call this it will return you back unique identifier randomly.

like image 125
Allamaprabhu Avatar answered Sep 20 '22 16:09

Allamaprabhu


You can use

[[UIDevice currentDevice] uniqueIdentifier]

However, this method is depreciated. In order to get a unique identifier for each device, you can still use CFUUIDCreateString and save the output to user defaults. Load this value each time the app runs. If the app is deleted and then reinstalled this value will be different.

If you do need a unique identifier across app installs you can use the network MAC address.

like image 30
bbarnhart Avatar answered Sep 20 '22 16:09

bbarnhart