4

Before deprecation of uniqueIdentifier it was good to use same identifier even deleting app and even erasing iPhone. After that I use MAC address and that was also working before iOS 7, but with iOS 7 it gives 2c:00:00:00:00:00. So I am not getting any way to get unique identifier. If is use IdentifierForVender: it gives different identifier if I delete the all the app of same vendor.

MAC Address : it works fine but not on iOS 7.

UniqueIdentifier :deprecated.

Please tell me the way to get unique value even app deletion and even erasing iPhone(like factory restore)

Kirsteins
  • 27,065
  • 8
  • 76
  • 78
user100
  • 327
  • 5
  • 19
  • try for iAdIdentifier... – prabu Nov 15 '13 at 07:32
  • You've pretty much listed all of the possibilities there, and it's not possible to have an automatically generated identifier that persists through all of those cases. The one that really catches me, though, is erasing devices - perhaps you should reconsider whether it is absolutely necessary to have this identifier that remains when a user clearly doesn't want it to! – ttarik Nov 15 '13 at 07:36
  • @prabu are you sure it gives unique identifier it i delete app and aslo if i erase the iphone? – user100 Nov 15 '13 at 07:37
  • @user2906829 The advertisingIdentifier does not persist like that, and can also be manually reset by the user from the Settings app. – ttarik Nov 15 '13 at 07:39
  • @ev0lution Yes it is neccessary to do this .Mac Address solved my problem but ios 7 distrubed it again it gives same as i wrote . please advise any tric. – user100 Nov 15 '13 at 07:40
  • @ev0lution Yes i see that. Is any way to store value in iphone that will be persist regardless erase the iphone? – user100 Nov 15 '13 at 07:41
  • No, there is no way to do that. Any method of storing it on the phone will be erased if the user reinstalls the OS. The best you can do is store a unique generated value in the keychain, or in the pasteboard. That will survive everything except an iOS reinstall. – borrrden Nov 15 '13 at 09:31
  • @ev0lution i have try both keychain and pasteboard but when i erase iphone both lost that . what shuld i do now . iphone can return any thing which is unique like ims ,or sim no... anything which is uniwue – user100 Nov 15 '13 at 09:52

5 Answers5

4

EDIT 3

Storing UUID in keychain seems to be next generic solution for this. This may solve issue for iOS7.


EDIT 2

Note: This solution in iOS 7 is no longer useful as uniqueIdentifier is no longer available from iOS7.


All possibilities and different ID maintenance are explained here.

enter image description here

For more details visit this link.


EDIT 1

This is the older approach but if you deadly need ID to retain even if system reset. Then you should look at this. This may help you.

I would like you to see at this popular link

1) MD5 of MAC+CFBundleIdentifier

[[UIDevice currentDevice] uniqueDeviceIdentifier]

This will remain same per app but different for each app. If you delete and reinstall your app it will be same per app. If you reset your system it will be same per app.

2) MD5 of the MAC

[[UIDevice currentDevice] uniqueGlobalDeviceIdentifier]

This will remain same for all app from same device. If you delete and reinstall your app it will be same per device. If you reset your system it will be same per device.

Community
  • 1
  • 1
βhargavḯ
  • 9,786
  • 1
  • 37
  • 59
  • that's nice, but he asks about iOS7 which is not in this chart – Antzi Nov 15 '13 at 07:35
  • 1
    I believe it's valuable information regardless. The chart shows that only the UDID persists through all of these cases, and the OP already knows that this is not available on iOS 7. – ttarik Nov 15 '13 at 07:38
  • But what about ios 7 UDID will unique on ios 7 if yes please tell me how to get it? – user100 Nov 15 '13 at 07:42
  • @βḧäṙℊặṿῗ i see that but there is problem they use key chain to store the unique id but when i erase the iphone then keychain lost the unique id. – user100 Nov 15 '13 at 10:01
  • @user2906829 yes when you reset your iphone means all content will also be erased. If you see chart above, you may notice only UDID will retain even if system reset. But unfortunately that is not accessible and allowed now. – βhargavḯ Nov 15 '13 at 10:21
  • @βḧäṙℊặṿῗ if i use your second edit then it will remain same for same app if i erase iphone ? – user100 Nov 15 '13 at 11:15
  • @user2906829 yes. Give it a try :) – βhargavḯ Nov 15 '13 at 11:17
2

Pretty much the only way to achieve this is to generate a random ID yourself (e.g. a UUID) and store it in the iOS keychain.

The keychain is not cleared when the app is uninstalled, so you should still be able to read the value back after a reinstall.

The other more straightforward persistent ID mechanisms have been blocked or banned by Apple.

grahamparks
  • 16,130
  • 5
  • 49
  • 43
  • but while erase iphone keychain lost that key . so please suggest some thing . and thanks for reply – user100 Nov 15 '13 at 09:53
  • @user2906829 There is nothing that will allow that. Apple have deliberately blocked all mechanisms that survive wiping the phone. – grahamparks Nov 15 '13 at 15:37
  • This solutions fails when you update application with different provision profile. For example from wildcard to some other. – B.S. Jan 28 '14 at 13:21
2

The fact that erasing iOS removes all unique IDs is completely intentional. Apple have purposefully made it difficult to get a unique ID that persists such events. This is for user privacy.

Apple doesn't care whether your application can track its users or not. Apple cares that it users are happy. And Apple's users expressed desire for more control over privacy settings, what apps can see and track etc. So Apple made all forms of unique ID difficult to obtain and persist for this exact reason.

Apple have provided APIs that can generate UUIDs for advertising/statistics/analytics tracking (described in other answers to this question). Use those IDs, because that is what they are intended for. MAC addresses were never intended to uniquely identify users.

You want to track a user. UDID and MAC addresses track devices, not users. Devices can be sold, gifted, lost or stolen. If you continue to use the same ID then you are not always tracking the same user. What if the user buys a new phone? Wouldn't you want an ID to follow them to the new device? Or is that a case where you don't care that the ID isn't persisted?

Furthermore, some users don't want to be tracked. Is that something you have considered? Are you providing a way for users to opt out? If you start tracking a user, and you use an ID that persists the app reinstall, persists the OS reinstall and there's no way for a user to opt out, how do they get you to stop tracking them?

The bottom line is that you really shouldn't be worrying about trying to get an ID that persists even past an OS reinstall.

To properly track a user you should make them create a user account.

Jasarien
  • 58,279
  • 31
  • 157
  • 188
1

You can use identifierForVendor for that because identifierForVendor is unique until application remove from device. When application again install into device then identifierForVendor will change.

For uniqueness you can save identifierForVendor into device keychain and next time when application install into device then check identifierForVendor is already saved into device keychain.

If "Yes" then use saved identifierForVendor, otherwise save new identifierForVendor into device keychain for further use.

-(void)checkAndSetDefaultKeychainsOfAppAndSetSecurityStatus
{
 KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] init];
 if (![wrapper searchKeychainCopyMatching:@"DeviceId"]) {
    [wrapper createKeychainValue:[UIDevice currentDevice].identifierForVendor.UUIDString forIdentifier:@"DeviceId"];
}
 self.strDeviceid = [wrapper getDataFromKeychainMatching:@"DeviceId"];
 NSLog(@"%@",self.strDeviceid);
 [wrapper release];
}

-(NSString *)stringforDeviceId
{
 KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] init];
 if (![wrapper searchKeychainCopyMatching:@"DeviceId"]) {
    [wrapper createKeychainValue:[UIDevice currentDevice].identifierForVendor.UUIDString forIdentifier:@"DeviceId"];
 }
 return [wrapper getDataFromKeychainMatching:@"DeviceId"];
}

Please let me know if you have any query. I will more then happy to clear.

Sandeep Agrawal
  • 425
  • 3
  • 10
-2

I found the answer. I wanted a unique id which will be same regardless deleting or erasing iPhone. I use serial No of Device so I can get the unique value all time.

There is a UIDevice category.

Kirsteins
  • 27,065
  • 8
  • 76
  • 78
user100
  • 327
  • 5
  • 19