2

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.

Developer
  • 1,435
  • 2
  • 23
  • 48

4 Answers4

2
[[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.

Maulik
  • 19,348
  • 14
  • 82
  • 137
1

UUID is deprecated in iOS 5, but you can always use MAC Address

How can I programmatically get the MAC address of an iphone

Community
  • 1
  • 1
X Slash
  • 4,133
  • 4
  • 27
  • 35
  • 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
0

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.

jww
  • 97,681
  • 90
  • 411
  • 885
0

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);
DShah
  • 9,768
  • 11
  • 71
  • 127