Get to the UUID and save the UUID inside the keychain.
This allows you to read back from the keychain even after uninstalling the app.
However, the UUID will change after the brush or reload system.
The code uses the Cfuuid+keychain implementation method:
1. Create a Keychain management class
@implementationZzkeychainmanager+ (Nsmutabledictionary *) Getkeychainquery: (NSString *) Service {return[nsmutabledictionary Dictionarywithobjectsandkeys: (__bridge_transferID) Ksecclassgenericpassword, (__bridge_transferID) Ksecclass, service, (__bridge_transferID) Ksecattrservice, service, (__bridge_transferID) Ksecattraccount, (__bridge_transferID) Ksecattraccessibleafterfirstunlock, (__bridge_transferID) ksecattraccessible, nil];}+ (void) Save: (NSString *) Service data: (ID) Data {//Get Search DictionaryNsmutabledictionary *keychainquery =[self getkeychainquery:service]; //Delete old item before add New itemSecitemdelete ((__bridge_retained cfdictionaryref) keychainquery); //Add New object to search dictionary (attention:the data format)[Keychainquery setobject:[nskeyedarchiver Archiveddatawithrootobject:data] Forkey: (__bridge_transferID) Ksecvaluedata]; //ADD item to keychain with the search dictionarySecitemadd ((__bridge_retained cfdictionaryref) keychainquery, NULL);}+ (ID) Load: (NSString *) Service {IDRET =Nil; Nsmutabledictionary*keychainquery =[self getkeychainquery:service]; //Configure the search setting[Keychainquery SetObject: (ID) kcfbooleantrue Forkey: (__bridge_transferID) Ksecreturndata]; [Keychainquery setobject: (__bridge_transferID) Ksecmatchlimitone Forkey: (__bridge_transferID) Ksecmatchlimit]; Cfdataref KeyData=NULL; if(Secitemcopymatching (__bridge_retained cfdictionaryref) keychainquery, (Cftyperef *) &keydata) = =NOERR) { @try{ret= [Nskeyedunarchiver unarchiveobjectwithdata: (__bridge_transfer NSData *) KeyData]; } @catch(NSException *e) {NSLog (@"unarchive of%@ failed:%@", service, E); } @finally { } } returnret;}+ (void) Deleteuuid: (NSString *) Service {nsmutabledictionary*keychainquery =[self getkeychainquery:service]; Secitemdelete ((__bridge_retained cfdictionaryref) keychainquery);}@end
2. Creating the UUID Management class
#import "ZZUUIDManager.h" @implementation zzuuidmanagerstatic nsstring * Const Key_in_keychain = @ "Com.zzuuid.uuid"; + ( void) Saveuuid: (NSString *) uuid{if (uuid && uuid.length > 0) {[Zzkeychainmanager Save:key_in_keychai N Data:uuid]; }}+ (NSString *) getuuid{nsstring *getudidinkeychain = (NSString *) [Zzkeychainmanager Load:key_in_keychain]; if (!getudidinkeychain | | [Getudidinkeychain isequaltostring:@ ""] | | [Getudidinkeychain Iskindofclass:[nsnull class]]) {Cfuuidref Puuid = cfuuidcreate (nil); Cfstringref uuidstring = cfuuidcreatestring (nil, puuid); NSString * result = (NSString *) cfbridgingrelease (cfstringcreatecopy (NULL, uuidstring)); Cfrelease (PUUID); Cfrelease (uuidstring); Getudidinkeychain = result; [Zzkeychainmanager Save:key_in_keychain Data:result]; Getudidinkeychain = (NSString *) [Zzkeychainmanager Load:key_in_keychain]; } return getudidinkeychain;} + (void) deleteuuid{[ZzkeychaInmanager Deleteuuid:key_in_keychain];}
3. Import #import "ZZUUIDManager.h"
Direct access
NSLog (@ "---->>uuid:%@", [Zzuuidmanager Getuuid]);
Reference: iOS get UUID
Get the iOS device UUID