In my app i want to create unique App ID foe every user..I heard about GUID which is used to create the unique Id for users.so how do i generate this GUID?Thanks in advance.
4 Answers
[[UIDevice currentDevice] uniqueIdentifier]
Returns the Unique ID of your iPhone.
If you need to create several UUID, just use this method:
+ (NSString *)GetUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}
NOTE : A UUID created by CFUUIDCreate is unique if a user uninstalls and re-installs the app: you will get a new one each time.
Also UUID is deprecated in iOS 5.

- 19,348
- 14
- 82
- 137
-
then what is the option in iOS5 – Developer Jan 19 '12 at 06:27
-
you can use MAC address of your device as X Slash has mentioned ! – Maulik Jan 19 '12 at 06:28
UUID is deprecated in iOS 5, but you can always use MAC Address
-
1@X Slash, is the MAC addr constant across network interfaces when the user shifts back and forth from Wi-Fi and cellular connections? – Crashalot Apr 09 '12 at 06:01
-
MAC address is fixed for any given network interface. A WiFi network card has a separate MAC address from a cellular network card for instance. – Stunner Sep 19 '12 at 00:58
This is somewhat off topic since you are asking about users, but you might also need something for a unique device (fingerprint). Have a look at Keychain Services Reference and three kSecAttrAccessible
constants: kSecAttrAccessibleAlwaysThisDeviceOnly
, kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
, and kSecAttrAccessibleWhenUnlockedThisDeviceOnly
.
The constants should help thwart copy/paste attacks assuming Apple generates a value coupled to a device, similar to [[UIDevice currentDevice] uniqueIdentifier]
. However, I have never verified the behavior in practice.

- 97,681
- 90
- 411
- 885
One more solution same as Maulik suggested...
This is about creating unique file names... But this can be apply to anything...that needs to be unique...
NSString *filePath;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectoryName"];
//Create unique filename
CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef newUniqueIdString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
path = [path stringByAppendingPathComponent:(NSString *)newUniqueIdString];
path = [path stringByAppendingPathExtension: @"MOV"];
CFRelease(newUniqueId);
CFRelease(newUniqueIdString);

- 9,768
- 11
- 71
- 127