By probably heard, Apple is deprecating, and attaining a UDID from an IOS device and furthermore T Hat they would be rejecting any app submissions that with the UDID in any the. The now deprecated to retrieving the UDID was:
NSString *udid = [[Uidevice currentdevice] identifier];
As we can no longer use this, but would often still have need of a unique identifier Apple has suggested using a cfuuid. To get a unique string identifier the need to does this:
Cfuuidref uuidref = cfuuidcreate (Kcfallocatordefault);
NSString *uuid = (NSString *) cfuuidcreatestring (KCFALLOCATORDEFAULT,UUIDREF);
This gives your a unique identifier However if you called these methods again you would get a different unique identifier W Hich may fine if you are ever need to the use of this identifier once but for many situations this is probably don't what do you w Ant. Apple suggests using Nsuserdefaults to store the UUID after you have made it. would do:
Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];
[Userdefaults setobject:uuid forkey:@ "uuid"];
Then if you need to retrieve the UUID on any point would call:
Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];
NSString *uuid = [userdefaults objectforkey:@ "UUID"];
This was an OK solution. I say it is only OK because the problem with nsuserdefaults are that they does not persist if the user removes and reinstalls Their application. This could wreak havoc in your app if for example the UUID was used to identify the device to a Web service that served dat A to your app. Your users would find it frustrating to lose their data simply because they the had reinstalled app.
A better solution is to store the UUID in the users keychain.
If you were unfamiliar with the concept it was fairly simple. Each app have its own keychain the can be used to securely store passwords, certificates, keys etc. The keychain can even be shared among several different apps if needed though I'll not cover that today.
To make working with the keychain simpler Apple wrote a objective-c wrapper class called Keychainitemwrapper which you CA N Find here.
To store our UUID in the keychain we first create a Keychainitemwrapper object with:
Keychainitemwrapper *keychainitem = [[Keychainitemwrapper alloc] initwithidentifier:@ "UUID" accessgroup:nil];
You can use whatever your want for the identifier. As I am only making this item available to this app I set the Accessgroup to nil.
Now-to-save your UUID to the keychain use:
[Keychainitem setobject:uuid Forkey: (ID) kuuid];
In this case I would has defined the constant kuuid with a # define such as:
#define KUUID @ "UUID"
To retrieve your UUID do a Keychainitemwrapper object and then call Objectforkey like this:
Keychainitemwrapper *keychainitem = [[Keychainitemwrapper alloc] initwithidentifier:@ "UUID" accessgroup:nil];
[Keychainitem Objectforkey: (ID) kuuid];
This UUID, that's stored in the keychain would now persist if the user removes the app and reinstalls and even if they save A encrypted backup and do a restore. It would not persist if they does a full reset of the device or restore from an unencrypted backup.
One word of warning, the keychain does not work in the IOS simulator.
Share and Enjoy:
What if Apple disables the UUID?