I have an application that uses rest to communicate to a server, i would like to obtain the iphones either mac address or device ID for uniqueness validation, how can this be done?
Every iPhone, iPod touch and iPad has a unique identifier number associated with it, known as a UDID (Unique Device ID). Your UDID is a 40-digit sequence of letters and numbers that looks like this: 00000000-000000000000000.
A Media Access Control (MAC) address is the unique hardware identifier of a NIC (Network Interface Card). A MAC address consists of two parts. The Block ID is the first six characters of a MAC address. The Device ID is the remaining six characters.
Every Apple iPhone, iPod touch and iPad has a unique device ID number associated with it, known as a Unique Device ID (UDID). Apple's device ID is a 40-digit sequence of letters and numbers. Customers can access their device ID numbers in iTunes or by downloading a free app from the Apple App Store.
[[UIDevice currentDevice] uniqueIdentifier]
is guaranteed to be unique to each device.
uniqueIdentifier (Deprecated in iOS 5.0. Instead, create a unique identifier specific to your app.)
The docs recommend use of CFUUIDCreate instead of [[UIDevice currentDevice] uniqueIdentifier]
So here is how you generate an unique id in your app
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault); NSString *uuidString = (NSString *)CFUUIDCreateString(NULL,uuidRef); CFRelease(uuidRef);
Note that you have to save the uuidString in user defaults or in other place because you can not generate the same uuidString again.
You can use UIPasteboard to store your generated uuid. And if the app will be deleted and reinstalled you can read from UIPasteboard the old uuid. The paste board will be wiped out when the device will be erased.
In iOS 6 they have introduced the NSUUID Class that is designed to create UUIDs strings
Also they added in iOS 6 @property(nonatomic, readonly, retain) NSUUID *identifierForVendor
to the UIDevice class
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 on the same device that come from different vendors, and for apps on different devices regardless of vendor.
The value of this property may be nil if the app is running in the background, before the user has unlocked the device the first time after the device has been restarted. If the value is nil, wait and get the value again later.
Also in iOS 6 you can use ASIdentifierManager class from AdSupport.framework. There you have
@property(nonatomic, readonly) NSUUID *advertisingIdentifier
Discussion Unlike the identifierForVendor property of the UIDevice, the same value is returned to all vendors. This identifier may change—for example, if the user erases the device—so you should not cache it.
The value of this property may be nil if the app is running in the background, before the user has unlocked the device the first time after the device has been restarted. If the value is nil, wait and get the value again later.
Edit:
Pay attention that the advertisingIdentifier
may return
00000000-0000-0000-0000-000000000000
because there seems to be a bug in iOS. Related question: The advertisingIdentifier and identifierForVendor return "00000000-0000-0000-0000-000000000000"
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