Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate UUID in ios

How to get a UUID in objective c, like in Java UUID is used to generate unique random numbers which represents 128 bit value.

like image 840
Saurabh Jadhav Avatar asked Jan 16 '13 06:01

Saurabh Jadhav


People also ask

How do I get UUID for iPhone?

How to Find Your iPhone and iPad's UUID. Connect your iPhone or iPad to your computer, and then open iTunes. Click the device icon at the top. Your device's UUID is hidden by default—click “Serial Number” and it will change to display your UUID.

What is iOS UUID?

Each iOS device has a UDID, or a Unique Device Identifier – a sequence of 40 characters that are unique to each individual device.

What is UUID in iOS Swift?

A universally unique value to identify types, interfaces, and other items.


2 Answers

Try:

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

UPDATE:

As of iOS 6, there is an easier way to generate UUID. And as usual, there are multiple ways to do it:

Create a UUID string:

NSString *uuid = [[NSUUID UUID] UUIDString]; 

Create a UUID:

[NSUUID UUID]; // which is the same as.. [[NSUUID] alloc] init];  

Creates an object of type NSConcreteUUID and can be easily casted to NSString, and looks like this: BE5BA3D0-971C-4418-9ECF-E2D1ABCB66BE

NOTE from the Documentation:

Note: The NSUUID class is not toll-free bridged with CoreFoundation’s CFUUIDRef. Use UUID strings to convert between CFUUID and NSUUID, if needed. Two NSUUID objects are not guaranteed to be comparable by pointer value (as CFUUIDRef is); use isEqual: to compare two NSUUID instances.

like image 91
Raptor Avatar answered Oct 10 '22 07:10

Raptor


Swift version of Raptor's answer:

let uuid = NSUUID().UUIDString 
like image 39
Melvin Avatar answered Oct 10 '22 08:10

Melvin