0

I am developing a program where I need to store a unique device_id since I cant get a unique identifier (like MAC Address) for every device, because it is deprecated by Apple.

What I want to do is, store a file in a specific directory of iOS where even the user deletes my iOS app this file wont be deleted. I am saying this because I used NSUserDefaults but the data stored from it get deleted if the user deletes its application.

*P.S Or if there is an alternative way to identify every device with its unique_id, suggestions are welcomed!*

E-Riddie
  • 14,660
  • 7
  • 52
  • 74
  • It's against the terms of your developer contract to uniquely identify a device in any way other than using the vendorIdentifier for the device, especially without user consent. – Jason Coco Feb 25 '14 at 08:47
  • Yes I have seen the documentation, but vendorforIdentifier returns the same value every time, and this is not what I want. – E-Riddie Feb 25 '14 at 08:50

2 Answers2

5

You should use KeyChain to save info that should not be deleted together with app. https://developer.apple.com/library/ios/documentation/Security/Reference/keychainservices/Reference/reference.html

UPDATE

This SO thread could be useful for you Saving/Reading to/from KeyChain

Community
  • 1
  • 1
Avt
  • 16,927
  • 4
  • 52
  • 72
  • are you sure keychain data isn't deleted if you delete the app? – jcesarmobile Feb 25 '14 at 08:45
  • KeyChain does not delete data because I have seen an example, but what I want to know is: If I save a value with a specific key in Keychain, accessing this value from other user for this key does return the same result? – E-Riddie Feb 25 '14 at 08:48
  • 2
    @jcesar The keychain *may* be purged if the device has no other apps installed with the same keychain group! but in practice it's never been. Now with iCloud Keychain, I doubt it ever will. – Jason Coco Feb 25 '14 at 08:49
  • 1
    @jcesar yes, I am sure. Common problem it is "How to delete data from keychain" not how to save it. http://stackoverflow.com/questions/4747404/delete-keychain-items-when-an-app-is-uninstalled – Avt Feb 25 '14 at 08:49
  • 1
    On MacOS every user account has its own keychain. Do we already have multiple user accounts for iOS7? – Avt Feb 25 '14 at 08:58
  • Avt that was simply a wonderfull answer! Thanks for your help! :) – E-Riddie Feb 25 '14 at 11:44
0

I need to store a unique device_id since I cant get a unique identifier

It is not 100% correct. You can use

[ UIDevice currentDevice ].identifierForVendor

From Apple's docs :

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.

Normally, the vendor is determined by data provided by the App Store. I the app was not installed from the app store (such as enterprise apps and apps still in development), then a vendor identifier is calculated based on the app’s bundle ID. The bundle ID is assumed to be in reverse-DNS format.

On iOS 6, the first two components of the bundle ID are used to generate the vendor ID. if the bundle ID only has a single component, then the entire bundle ID is used. On IOS 7, all components of the bundle except for the last component are used to generate the vendor ID. If the bundle ID only has a single component, then the entire bundle ID is used.

Avt
  • 16,927
  • 4
  • 52
  • 72
  • I dont need to use the same id for every device. I want to identify device and for every device gets its unique id, but this is not allowed by apple, thats why I am asking about saving data without beeing deleted when the app gets uninstalled. – E-Riddie Feb 25 '14 at 09:35
  • "A different value is returned ... and for apps on different devices regardless of vendor." For different devices it is different! – Avt Feb 25 '14 at 09:37
  • Refer to the first paragraph and you will understand what I am saying. The same device it refers to iPhone 4, 4s, 5, 5s. That means Ill have only 4 unique id. This was the problem that made me start looking for another way to identify a specific device like MAC Address does. – E-Riddie Feb 25 '14 at 09:46
  • I do not think "devices" - is a model here. I think "devices" means particular instance. – Avt Feb 25 '14 at 09:57
  • Maybe, I don't know exactly but the idea is that I have tried it on my app and this was a major bug, because it generated the same values in 3 iPhone 5. – E-Riddie Feb 25 '14 at 11:42
  • Thank you for information. I am using it in my current project. May be I need to check does it work as I expect or not. – Avt Feb 25 '14 at 11:54