+ (NSString*)identifierForVender{
UICKeyChainStore *keyChain = [UICKeyChainStore keyChainStore];
NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
bool keyExist = [keyChain contains:bundleID];
NSString *uuidStr = nil;
if (keyExist) {
uuidStr = [keyChain stringForKey:bundleID];
return uuidStr;
}
uuidStr = [[[[UIDevice currentDevice] identifierForVendor] UUIDString] stringByAppendingString:bundleID];
NSLog(@"uuidStr2:%@",uuidStr);
[keyChain setString:uuidStr forKey:bundleID];
return uuidStr;
}
- 对于同一个设备上的com.company.app1 和com.company.app2 含有相同的IDFV,所以在最后再拼接一个BundleID即可标志整个UUID唯一(服务端根据这个UUID映射Token,这样尽管用户重装APP,UUID不变,覆盖旧的Token即可)
- IDFV会变化的几种情况(参考)
- 变化的情况:删除手机上所有相同Vendor后再安装新的,TestFlight安装的,还有ad-hoc安装的;