How to get a UUID in objective c, like in Java UUID is used to generate unique random numbers which represents 128 bit value.
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.
Each iOS device has a UDID, or a Unique Device Identifier – a sequence of 40 characters that are unique to each individual device.
A universally unique value to identify types, interfaces, and other items.
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.
Swift version of Raptor's answer:
let uuid = NSUUID().UUIDString
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With