Reputation: 327
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)
Upvotes: 4
Views: 1949
Reputation: 327
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.
Upvotes: -2
Reputation: 9836
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.
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.
Upvotes: 4
Reputation: 425
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.
Upvotes: 1
Reputation: 58458
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.
Upvotes: 2
Reputation: 16296
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.
Upvotes: 2