16

Looking for your help

I am facing a problem while getting Device Identifier. Actually I am using a UIDevice+IdentifierAddition.h, NSString+MD5Addition.h classes to get Identifier, but its return same identifier for all my devices i.e. iPhone 4s (iOS 7.1) & iPhone 5 (iOS 7.1.1).

Can any one have any solution for this problem. because I want a something unique for device specific. its my app requirement.

Important: I want to submit this app on app store, So please, answer must be as per the guidelines

icodebuster
  • 8,890
  • 7
  • 62
  • 65
Karamjeet Singh
  • 460
  • 1
  • 5
  • 16
  • Have you check with the UUID ..? **https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSUUID_Class/Reference/Reference.html** – Kumar KL Jul 15 '14 at 08:43
  • possible duplicate: http://stackoverflow.com/questions/7273014/ios-unique-user-identifier/8677177#8677177 – Mateusz Szlosek Jul 15 '14 at 08:56
  • @KumarKL Thanks for your reply. its return UUID which means its give different identifier on every launch of app. I need something like UDID. Which will be unique for every device. – Karamjeet Singh Jul 15 '14 at 09:01
  • @MateuszSzlosek thanks for your reply. if you had gone through with the link you provide me there is a comment by Drabuna that it return new UUID every time. But I need something unique which is a device specific like UDID. – Karamjeet Singh Jul 15 '14 at 09:07
  • 1
    @karam There's a solution with storing UUID in keychain. You'll generate this once and later read this value from keychain on the next launch. – Mateusz Szlosek Jul 15 '14 at 09:21
  • @MateuszSzlosek thanks for your reply. I have already implemented it. Hope apple will not have any issue with it. – Karamjeet Singh Jul 15 '14 at 10:15

6 Answers6

27

Since iOS 7 it is no longer possible to get any unique device identifiers.

Your options are:

Community
  • 1
  • 1
rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • +1 and to be complete, here is the link saying that the unique device identifiers stopped after iOS6.1 https://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instp/UIDevice/uniqueIdentifier – HpTerm Jul 15 '14 at 09:18
  • @rckoenes thanks for your reply. I have already implemented it. Hope apple will not have any issue with it. – Karamjeet Singh Jul 15 '14 at 10:16
  • @rckoenes-for the 1st option(create your own unique ID and save it in the keychain.) Is there a way user can reset this by reseting location and privacy on one's device or by a factory reset? – rak appdev Oct 24 '16 at 22:17
  • @rakappdev Yes it is possible that the user resets this. But if the user has their keychain in the cloud you value should be saved there. Another option is to save the key on the user iCloud drive. But there is not way to restrict it to a phyiscal device not should you. – rckoenes Oct 25 '16 at 07:15
15

Now it's possible in iOS 11.0+, Apple has introduced a new API called DeviceCheck API with which developers can uniquely identify a device.

As mentioned in the documentation:

Using the DeviceCheck APIs, in combination with server-to-server APIs, you can set and query two bits of data per device, while maintaining user privacy. You might use this data to identify devices that have already taken advantage of a promotional offer that you provide, or to flag a device that you have determined to be fraudulent. The DeviceCheck APIs also let you verify that the token you receive comes from an authentic Apple device that includes your app.

Also, check out the following WWDC17 video starting at 24 min: https://developer.apple.com/videos/play/wwdc2017/702/


EDIT:

A thoroughly detailed tutorial on this Device Check topic can be found here.

Muhammad Umair
  • 1,664
  • 2
  • 20
  • 28
  • 1
    This will work a bit differently then a Unique identifier, as you can not store this on your server. But it does allow your app to store 2 bits, yes 2 bits, of data on a server at Apple. Which it can retrieve in the app. – rckoenes Mar 07 '18 at 09:51
  • The WWDC17 video seems to be no longer available – Simon Pickup Sep 04 '22 at 17:06
8

In Objective c

NSString *uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

In Swift

 var uniqueId=UIDevice.currentDevice().identifierForVendor.UUIDString as String
 println("Your device identifires =>\(uniqueId)")
Avijit Nagare
  • 8,482
  • 7
  • 39
  • 68
  • 1
    This will change each time that the application is re-installed. It's not a true UDID. – Nathan F. May 03 '17 at 21:05
  • @NathanFiscaletti Are you testing on simulator ? test on real device. – Avijit Nagare May 10 '17 at 16:16
  • No, I'm testing on real devices. The way that identifierForVendor works is that once all apps from the vendor are removed the identifierForVendor is reset to a new identifier. It's only meant for sharing a value between a specific vendors applications. – Nathan F. May 11 '17 at 02:49
  • 2
    @NathanFiscaletti Thanks. identifierForVendor 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. Instead, use NSUUID to generate a custom UUID and store that in the keychain (because the keychain isn't deleted if the app is deleted and reinstalled). – Avijit Nagare May 11 '17 at 08:02
5

Unfortunately identifierForVendor changes when you uninstall your application so to guarantee that the it will not change save it in the keychain

I used pod 'SSKeychain' Homepage: https://github.com/soffes/sskeychain

Here is the code

 + (NSString *)getDeviceId {
           NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];
           NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"MY_KEY"];
           if (strApplicationUUID == nil) {
               strApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
               [SSKeychain setPassword:strApplicationUUID forService:appName account:@"MY_KEY"];
            }
    return strApplicationUUID;
}
nahlamortada
  • 489
  • 6
  • 16
0

[UIDevice uniqueIdentifier]; is deprecated in ios 5 and above.

You can get identifier for vendor using this NSString *udid = [[UIDevice currentDevice] uniqueIdentifier];

and store this in keychain and use later on.

Also you can check for 1) NSUUID 2)CFUUID

you will get detail description here Unique device identification in ios

Nik
  • 1,679
  • 1
  • 20
  • 36
0

If you're trying to identify a device only once i.e., to estimating the number of unique users then I suggest using "advertisingIdentifier" of ASIdentifierManager.

Apple Doc

Mahesh
  • 1,472
  • 1
  • 9
  • 16