The program that accesses Uidids is no longer audited, and the alternative is that developers should use the vendor or advertising identifiers described in iOS 6.
Apple has warned us that uniqueidentifier will no longer be able to use it. , and two additional options are available. But which do you choose to use in the program? This article will not answer this question, specifically which is for you to make decisions based on the purpose of the program.
below I will list the currently supported iOS And the deprecated unique identifier method, and the corresponding explanation, I hope you look at the use of the unique identifier, you can make the correct determination.
cfuuid cfuuidcreate method is used to create CFUUIDREF, and you can get a corresponding nsstring, as follows:
" /span>
- Cfuuidref cfuuid =cfuuidcreate (Kcfallocatordefault);
- NSString *cfuuidstring = (nsstring*) cfbridgingrelease (cfuuidcreatestring (Kcfallocatordefault, Cfuuid));
Copy Code
The system is not stored for this cfuuid value. Each time you call Cfuuidcreate, the system returns a new unique identifier. If you want to store this identifier, you need to store it yourself in Nsuserdefaults, Keychain, pasteboard, or somewhere else.
Example: 68753a44-4d6f-1226-9c60-0050e4c00067
NsuuidNsuuidappears in iOS 6, which is almost exactly the same as cfuuid, except that it is the Objective-c interface. + (ID) UUIDis a class method that calls the method to obtain a UUID. A UUID string can be obtained by using the following code:
- NSString *uuid =[[nsuuid uuid] uuidstring];
Copy Code
< Span style= "Font-size:small;" As with Cfuuid, this value system is not stored and a new unique identifier is obtained each time it is called. If you want to store it, you need to store it yourself. When I read nsuuid, I noticed that this value was exactly the same as cfuuid (though it might not be the same):
ad identifier (idfa-identifierforidentifier) advertisingidentifier is part of the new framework adsupport.framework. The Asidentifiermanager Singleton provides a method for Advertisingidentifier, which returns a Nsuuid instance mentioned above by calling the method.
- NSString *adid =[[[asidentifiermanager Sharedmanager] advertisingidentifier] uuidstring];
Copy Code
Unlike Cfuuid and Nsuuid, ad identifiers are stored by the system. However, even though this is stored by the system, there are several cases where the ad identifier is regenerated. This ad identifier is regenerated if the user completely resets the system (restore location and privacy, general-purpose, Setup, and so on). In addition, if the user explicitly restores the ads (set-up, general-purpose, and so on, to the ads, and restore the ad identifiers), then the ad identifiers will be regenerated. With respect to the restoration of the ad identifier, it is important to note that if the program is running in the background, the user "restores the ad identifier" and then goes back to the program, and then gets the ad identifier and does not immediately get the restored identifier. You must terminate the program before restarting the program to obtain the restored AD identifier. I guess this is because Asidentifiermanager is a single case.
the user has a controllable switch to "limit ad tracking" for the ad identifier. Nick Arnott's article has been pointed out . Turn this switch on and actually do nothing, but that's what you want to limit your access to the ad identifier. This switch is a simple Boolean flag, and when you send the ad identifier to any server side, you'd better judge the value and then make the decision.
Example: 1e2dfa89-496a-47fd-9941-df1fc4e6484a
Vindor designator (IDFV-identifierforvendor)This is also added to iOS 6, but the new method of getting this IDFV is added to the existing Uidevice class. As with Advertisingidentifier, this method returns a Nsuuid object.
- NSString *IDFV =[[[uidevice Currentdevice] Identifierforvendor] uuidstring];
Copy Code
Apple's Official document has the following description of Identifierforvendor:
The value of this property is the same for apps, come from the same vendor running on the same device. A different value is returned for apps on the same device this come from different vendors, and to apps on different Devi Ces regardless of vendor.
If such a condition is met, then the obtained value of this property will not change: the same device inside the same program-the same vindor-. If this is the case, then this value will not be the same: the same program-the same device-different vindor, or the same program-different devices-whether or not the same vindor.
After reading the above, I have a question like "What is Vendor". The first thing I think about is the Apple developer account. But it turns out to be wrong. And then I thought maybe there was a appidentifierprefix thing, like keychain access, can be shared among multiple programs. The same is true of the idea. Finally, vendor is very simple: a vendor is the first two parts of the cfbundleidentifier (reverse DNS format). For example, COM.DOUBLEENCORE.APP1 and com.doubleencore.app2 get the same Identifierforvendor because the first two parts of their cfbundleidentifier are the same. But the Identifierforvendor is completely different: com.massivelyoverrated or Net.doubleencore.
one thing to note here is that if the user uninstalls all the programs for the same vendor and then re-installs the program provided by the same vendor, Identifierforvendor will be reset at this point.
Example: 599f9c00-92dc-4b5c-9464-7971f01f8370
UDID
available in previous versions, but in IOS5 and later versions, and deprecated. Although this udid is used extensively, it has to be said that it is slowly moving away from the developer and cannot consider using UDID. It remains to be seen whether the identifier is to be private or to be removed entirely from a later version of iOS. However, this udid is very handy when deploying an enterprise-class signature program. Here's how to get Udid:
- NSString *udid =[[uidevice Currentdevice] uniqueidentifier];
Copy Code
Example: BB4D786633053A0B9C0DA20D54EA7E38E8776DA4
Openudid when iOS 5 was released, uniqueidentifier was deprecated, causing the vast majority of developers to look for a solution that would replace Udid and not be controlled by Apple. This Openudid became the most widely used open source Udid alternative. Openudid is easy to implement in engineering and supports a range of advertising providers.
- NSString *openudid = [Openudid value];
Copy Code
Openudid has used a very ingenious method of storing identifiers between different programs-a special name used to store identifiers in the pasteboard. In this way, other programs (also using Openudid) know where to go to get the identifiers that have been generated (instead of generating a new one).
As already mentioned, in the future, Apple will start forcing the use of advertisingidentifier or Identifierforvendor. If this day comes, even openudid looks like a great choice, but you may have to transition to Apple's approach.
Example: 0d943976b24c85900c764dd9f75ce054dc5986ff
SummaryHopefully the information above will help you choose the right unique identifier for your program use. Here, I created a small unique identifier test program , you can run the program and look at what is displayed (including all the identifiers mentioned above). In addition, there are two tables in the table that describe two things: usability in iOS, and when to get a reset identifier.
<ignore_js_op>
* The program must be restarted to see the effect of the change.
* * Remove All programs provided by the same vendor to see the changed values.
(go) Unique identifiers in iOS