Recently in a project, the project did not register for login, but instead used a unique ID to indicate the user. This unique ID is basically used by IDFV. So, the question is, how to get the user to uninstall the app and install the app again in the same account.
First introduce the following IDFV:
IDFV (Identifierforvendor) is the first two parts of the cfbundleidentifier (reverse DNS format). For example, the bundle ID of an app is Com.companyName.appname, then IDFV is com.companyname. Applications from the same carrier run on the same device, the value of this property is the same, different operator applications run on the same device, or the same carrier's app runs on different devices.
After testing, as long as there is a Tencent app on the device, reinstall the Identifierforvendor value unchanged, if the Tencent app is all removed, reinstall the Identifierforvendor value change.
It is certainly not possible to deposit IDFV into Nsuserdefaults, because once the application is uninstalled, the data will no longer exist and IDFV may change. Keychain won't do that. Then introduce the following keychain:
we can think of keychain as a dictionary, all the data is stored in key-value form, you can do the add, update, GET, delete four operations on this dictionary. For each application, keychain has two access areas, private and public areas. The private area is a sandbox, and any data stored by this program is not visible to other programs. In order to put the stored content in the public area, you need to declare the name of the public area, the official document tube name is called "Keychain Access Group", the method is to create a new plist file, the name casually, the contents are as follows:"YourAppID.com.yourCompany.whatever" is the name of the public area you want to play, in addition to the whatever field can be arbitrarily set aside, the others must be truthfully filled out. The path of this file is to be configured in Project->build Setting->code Signing entitlements, otherwise the public area is invalid, after the configuration, must use your official certificate signature compiles only then can pass, Otherwise Xcode will frame the box to tell you that code signing has a problem. So, Apple restricts you to share keychain data with your company's products, and other companies won't be able to access your company's products keychain.
The iOS Keychain service provides a secure way to save private information (passwords, serial numbers, certificates, and so on), and each iOS program has a separate keychain store. Compared to nsuserdefaults, file preservation and other general way, keychain save more secure, and keychain saved information will not be deleted because the app is lost, so after reloading the app, keychain data can also be used. in the application using keychain, we need to import security.framework, Keychain operation Interface declaration in the header file SecItem.h. Using the SecItem.h method to operate the keychain, the code needs to be written more complex, in order to alleviate the development of our programmers, we can use some of the packaged tools, Apple's official proposed two tool classes: Keychainitemwrapper and Sfhfkeychainutil S I'm using a keychainitemwrapper. Download the keychainitemwrapper and copy the "KeychainItemWrapper.h" and "KEYCHAINITEMWRAPPER.M" to our project, and import Security.framework Here's My code in APPDELEGATE.M: Because I don't need to share the content in keychain between apps, Accessgroup is set to nil
-(nsstring *) GETIDFV
{
nsstring *str;
keychainitemwrapper *keychainitem = [[keychainitemwrapperalloc ]initwithidentifier:@ "UUID"accessgroup: nil];
MYLog(@ "%@", [Keychainitem objectforkey: (__bridge ID ) ksecvaluedata]);
nsstring *uuidstr = [Keychainitemobjectforkey:(__ BridgeID)ksecvaluedata];
MYLog(@ "%@", [[Uidevice Currentdevice] identifierforvendor]);
if ([uuidstriskindofclass: [nsdictionary class ]) {//means there is no value stored
nsstring *myuuidstr = [[[uidevicecurrentdevice] Identifierforvendor ]uuidstring];
[Keychainitemsetobject: myuuidstrforkey:(__bridge ID)ksecvaluedata];
str = MYUUIDSTR;
}
Else{
str = [Keychainitemobjectforkey:(__bridgeID )ksecvaluedata];
}
MYLog(@ "======%@", str);
return str;
}
This is my summary of keychain preservation IDFV, if there is a mistake, please correct me. Make progress together and improve together. If you use the content in a shared keychain, then summarize it.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Save iphone Unique ID with keychain IDFV