[IOS] user identification methods available for iOS8 (idfa, UUID, idfv)
To track and count users, you naturally need a Unique User Identifier, which is a problem facing every company. There are many unique identifiers in history, such as UDID, MAC address, and OpenUDID. I will not describe how they got down one by one, but now only idfa, idfv, UUID + keyChain are useful.
Idfa (Advertising Identifier): It can be understood as an advertisement id, which apple provides to track users.
Disadvantage: You can set-privacy-advertisement-Restore ad identifier to restore, and then get a new identifier;
IOS> = 6.0.
Usage:
#import NSString *idfa= [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
Idfv (identifierForVendor): The unique identifier provided by apple to Vendor. Vendor represents the application developer. In actual use, a Vendor is the first two parts of CFBundleIdentifier (reverse DNS format. For example, the idfv obtained by com. baidu. tieba and com. baidu. image are the same, because the first two parts of their CFBundleIdentifier are the same.
Disadvantage: After all the applications of the same developer are uninstalled, The idfv obtained by re-installation will be different. Assume that the mobile phone is installed with two company apps,
Requirements: iOS & gt; = 6.0
Usage:
NSString *idfv = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
UUID (Universally Unique Identifier): A universal unique identifier. Each generation is different. Therefore, the key string must be saved after the first generation, so that the key string can be obtained even if the application is deleted and reinstalled.
Usage:
There are many UUID generation methods. Only one is written here. Generate a UUID:
-(NSString*) uuid { CFUUIDRef puuid = CFUUIDCreate( nil ); CFStringRef uuidString = CFUUIDCreateString( nil, puuid ); NSString * result = (NSString *)CFBridgingRelease(CFStringCreateCopy( NULL, uuidString)); CFRelease(puuid); CFRelease(uuidString); return result;}
Store UUID in the key string. A third-party tool SFHFKeychainUtils is used here. github address
[SFHFKeychainUtils storeUsername:@UDID andPassword:[self uuid] forServiceName:@ZYB updateExisting:1 error:nil];
Remove UUID from the key string:
[SFHFKeychainUtils getPasswordForUsername:@UDID andServiceName:@ZYB error:nil]
NOTE: If no storage is available, crash will be taken out directly.