Is possible to discover the iOS device identifier, using Xcode. I need to each app downloaded have a unique identifier. I thought in generate random numbers, but they might generate the same number more than once! Anyone have an idea?
7 Answers
In UIDevice class apple has provided method uniqueIdentifier but now its deprecated(for iOS5), In method's documentation you will find how you can use uniqueIdentifier.

- 8,544
- 3
- 20
- 19
I've found a pretty simple way to do this, here's how:
Press COMMAND + N and select Cocoa Touch Class
.
Name your class NSString+UUID
and hit next.
Then, replace the code in NSString+UUID.h
with:
@interface NSString (UUID)
+ (NSString *)uuid;
@end
And in NSString+UUID.m
with:
@implementation NSString (UUID)
+ (NSString *)uuid {
NSString *uuidString = nil;
CFUUIDRef uuid = CFUUIDCreate(NULL);
if (uuid) {
uuidString = (NSString *)CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
}
return [uuidString autorelease];
}
@end
Now, when you need to get the UUID (i.e: store it using NSUserDefaults when your app loads):
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
NSString *userIdentifierKey = @"user-identifier"
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:userIdentifierKey] == nil) {
NSString *theUUID = [NSString uuid];
[defaults setObject:theUUID forKey:userIdentifierKey];
[defaults synchronize];
}
// additional application setup...
return YES;
}

- 2,640
- 5
- 44
- 62
iOS6 provides a new replacement [[[UIDevice currentDevice] identifierForVendor] UUIDString]
The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps onthe same device that come from different vendors, and for apps on different devices regardles of vendor.

- 2,871
- 1
- 23
- 28
Try this UIDevice-with-UniqueIdentifier-for-iOS-5, it uses the device's mac address as unique identifier.

- 18,599
- 12
- 71
- 109
-
do you know if the MAC addr remains constant across Wi-Fi and cellular connections, or does it change when the user switches from one type of network to the other? – Crashalot Apr 09 '12 at 06:05
You can create a category of UIApplication , UIDevice or as you prefere like this (ARC example)
@interface UIApplication (utilities)
- (NSString*)getUUID;
@end
@implementation UIApplication (utilities)
- (NSString*)getUUID {
NSUserDefaults *standardUserDefault = [NSUserDefaults standardUserDefaults];
static NSString *uuid = nil;
// try to get the NSUserDefault identifier if exist
if (uuid == nil) {
uuid = [standardUserDefault objectForKey:@"UniversalUniqueIdentifier"];
}
// if there is not NSUserDefault identifier generate one and store it
if (uuid == nil) {
uuid = UUID ();
[standardUserDefault setObject:uuid forKey:@"UniversalUniqueIdentifier"];
[standardUserDefault synchronize];
}
return uuid;
}
@end
UUID () is this function
NSString* UUID () {
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
return (__bridge NSString *)uuidStringRef;
}
this generate an unique identifier stored into the NSUserDefault to be reused whenever the application need it - This identifier will unique related to the application installs not to the device, but can be used for example to take trace about the number devices subscribed the APN service etc...
After that you can use it in this way:
NSString *uuid = [[UIApplication sharedApplication] getUUID];

- 788
- 5
- 10
Use this: [[UIDevice currentDevice] identifierForVendor]
For more information take a look to this answer

- 1
- 1

- 4,834
- 3
- 44
- 62
try this
- (NSString *)getDeviceID
{
NSString *uuid = [self gettingString:@"uniqueAppId"];
if(uuid==nil || [uuid isEqualToString:@""])
{
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
if (theUUID)
{
uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID));
[self savingString:@"uniqueAppId" data:uuid];
[uuid autorelease];
CFRelease(theUUID);
}
}
return uuid;
// this is depreciated
// UIDevice *device = [UIDevice currentDevice];
// return [device uniqueIdentifier];
}

- 948
- 1
- 8
- 18