8 Kinds of iOS acquisition device Unique identification method, hope to be useful to everyone.
UDID
UDID (Unique Device Identifier), the unique identifier for the IOS device, is a 40-bit hexadecimal sequence (jailbreak devices can change the device's UDID through certain tools), and mobile networks can use UDID to identify mobile devices.
Many developers associate UDID with the user's real name, password, address, and other data, and the network Snoop collects the data from multiple applications and then gets a lot of privacy data from that person, and most applications do transmit UDID and private information frequently. To avoid a class-action lawsuit, Apple finally decided to abolish the practice when it was 5 in IOS.
Application attempts now to acquire UDID have been banned and are not allowed on shelves.
MAC Address
MAC (Medium/media Access Control) address, which represents the identifier for each site on the Internet, is a six-byte (48-bit) hexadecimal sequence. The first three bytes are the "unique identifier (organizationally unique Identifier)" assigned to different manufacturers by the IEEE Registration Authority RA, and the latter three bytes are assigned by each manufacturer to the production adapter interface, called the extension designator.
MAC addresses are used on the network to differentiate the uniqueness of devices, and the devices that access the network have a MAC address, and they are definitely the only ones. An iPhone may have multiple MAC addresses, including WiFi, SIM, and so on, but ITouch and the IPad have a WiFi, so just get the WiFi MAC address. A MD5 (MAC address + Bundleid) is generally taken to obtain a unique identifier.
But the MAC address, like UDID, has a privacy problem, and after IOS 7, all devices request a MAC address to return a fixed value, and this method is self-defeating.
Openudid
UDID is discarded, the vast majority of developers need to look for an alternative UDID, and not under the control of Apple, thus, Openudid became the most widely used open source UDID alternatives. Openudid uses a very ingenious way to store identifiers between different programs: A special name is used in the pasteboard to store identifiers, and other applications can be acquired by this method.
Apple has restricted the pasteboard after IOS 7, resulting in an inability to share a openudid between applications on the same device.
UUID + Store Yourself
UUID (Universally unique IDentifier), a universal unique identifier, is a 32-bit hexadecimal sequence that uses a dash to connect: 8-4-4-4-12 through Nsuuid (after IOS 6) [Nsuuid UUID]. Uuidstring or Cfuuid (after IOS 2) cfbridgingrelease (cfuuidcreatestring (Kcfallocatordefault, Cfuuidcreate ( Kcfallocatordefault)) to get it, but each time the value is different, you need to store it yourself.
Push token + Bundleid
Push token guarantee that the device is unique, but must have network conditions to work, the method does not depend on the device itself, but relies on the apple push, and Apple push is sometimes exhausting.
Idfa
Idfa-identifierforidentifier (AD designator), all apps on the same device will get the same value, which is set by Apple to keep track of users by offering commercial ads. Although the IPhone defaults to allow tracking, and the general user does not know that there is such a setting, but the user can be in the settings-privacy-advertising tracking to reset the value of this ID, or limit the use of this ID, so it is possible to get no value.
Idfv
Idfv-identifierforvendor (vendor designator), obtained by [Uidevice currentdevice].identifierforvendor.uuidstring. is matched by the first two parts of the inversion of Bundleid, if the same is the same vendor, for example, for the two bundleid of Com.mayan.app_1 and com.mayan.app_2, belonging to the same vendor, sharing the same IDF V, unlike IDFA, the value of IDFV is bound to be fetched, so it is ideal for identifying users as the primary ID for internal user behavior analysis. But the user deletes the app, the IDFV value is reset, the app is installed again, and the IDFV value is different from the previous.
IDFV + Keychain
Through the above several storage unique identification method analysis, summarizes each has the merit and disadvantage. Many methods have been banned by Apple or too many loopholes, is increasingly not used by developers, now Apple main push IDFA and IDFV these two methods, respectively external and internal, but IDFV will change when the APP reinstall, so my method is through the first generation of IDFV storage to keychain, after each The secondary get identifiers are obtained from the keychain.
#import <UIKit/UIKit.h>
@interface myvendortoll:nsobject
+ (NSString *) GETIDFV;
@end
#import "MYVendorToll.h"
#import "MYKeyChainTool.h"
@implementation myvendortoll
+ (NSString *) GETIDFV
{
NSString *IDFV = (NSString *) [Mykeychaintool load:@ "IDFV"];
if ([IDFV isequaltostring:@ ""] | |! IDFV) {
IDFV = [Uidevice currentdevice].identifierforvendor.uuidstring;
[Mykeychaintool save:@ "IDFV" DATA:IDFV];
}
return IDFV;
}
@end
#import <Foundation/Foundation.h>
@interface mykeychaintool:nsobject
+ (void) Save: (NSString *) Service data: (ID) data;
+ (ID) Load: (NSString *) service;
+ (void) Deletekeydata: (NSString *) service;
@end
#import "MYKeyChainTool.h" @implementation Mykeychaintool + (nsmutabledictionary *) Getkeychainquery: (NSString *) Servi Ce {return [nsmutabledictionary Dictionarywithobjectsandkeys: (ID) Ksecclassgenericpassword, (ID) ksecclass, service,
(ID) Ksecattrservice, service, (ID) ksecattraccount, (ID) ksecattraccessibleafterfirstunlock, (ID) ksecattraccessible,
NIL]; } + (void) Save: (NSString *) service data: (ID) data {//get Search dictionary nsmutabledictionary *keychainquery = [Self g
Etkeychainquery:service];
Delete old item before add New Item Secitemdelete ((CFDICTIONARYREF) keychainquery); Add new object to search dictionary (attention:the data format) [Keychainquery setobject:[nskeyedarchiver Archiveddataw
Ithrootobject:data] Forkey: (ID) ksecvaluedata];
ADD item to keychain with the search Dictionary Secitemadd ((cfdictionaryref) keychainquery, NULL);
} + (ID) Load: (NSString *) Service {ID ret = nil; Nsmutabledictionary *keychainquery = [self getkeychainquery:service];
Configure the search setting//since in my simple case we are are expecting only a single for be returned (the Password) We can set the attribute ksecreturndata to Kcfbooleantrue [keychainquery setobject: (ID) kcfbooleantrue Forkey: (i
d) Ksecreturndata];
[Keychainquery setobject: (ID) ksecmatchlimitone Forkey: (ID) ksecmatchlimit];
Cfdataref keyData = NULL; if (secitemcopymatching (Cfdictionaryref) keychainquery, (Cftyperef *) &keydata) = = NOERR) {@try {ret = [nskeyedu
Narchiver unarchiveobjectwithdata: (__bridge NSData *) KeyData];
} @catch (NSException *e) {NSLog (@ "Unarchive of%@ failed:%@", service, E);
@finally {}} if (KeyData) cfrelease (keyData);
return ret;
} + (void) Deletekeydata: (NSString *) Service {nsmutabledictionary *keychainquery = [self getkeychainquery:service];
Secitemdelete ((cfdictionaryref) keychainquery);
} @end
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.