Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Device ID from an iOS app?

How can I get the unique ID of the user's device in an iOS app?

like image 864
sujay Avatar asked Mar 29 '11 06:03

sujay


2 Answers

use this

    UIDevice *device = [UIDevice currentDevice];
    NSString *uniqueIdentifier = [device uniqueIdentifier];

Update

Apple has the deprecated unique identifier, so now the following code (from Melvin Sovereign's comment) is appropriate:

NSString *uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
like image 177
Iqbal Khan Avatar answered Oct 23 '22 13:10

Iqbal Khan


Interestingly, Apple has since deprecated the uniqueIdentifier in iOS 5. Here's the relevant TechCrunch article: http://techcrunch.com/2011/08/19/apple-ios-5-phasing-out-udid/

Apple suggests that you no longer uniquely identify the device but instead identify the user. In most cases, this is excellent advice though there are some situations which still require a globally unique device ID. These scenarios are quite common in advertising. Hence, I wrote an extremely simple drop-in library which replicates the existing behavior exactly.

In a shameless plug of self promotion, I'll link it here in the hope that someone finds it useful. Also, I welcome all and any feedback/criticism: http://www.binpress.com/app/myid/591

like image 35
Sam Stewart Avatar answered Oct 23 '22 14:10

Sam Stewart