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?
A unique device identifier (UDID) is a 40-character string assigned to certain Apple devices including the iPhone, iPad, and iPod Touch. Each UDID character is a numeral or a letter of the alphabet. Using the UDID, third parties, particularly app vendors, can track subscriber behavior.
A device ID is a unique, anonymized string of numbers and letters that identifies every individual smartphone or tablet in the world. It is stored on the mobile device and can be retrieved by any app that is downloaded and installed. Apps typically retrieve the ID for identification when talking to servers.
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.
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;
}
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