[IOS] saves the unique ID of the user and the id of the ios storage.
IOS's keychain Service provides a secure way to store private information (passwords, serial numbers, certificates, etc.). Each ios program has an independent keychain storage. Compared with NSUserDefaults and file storage, keychain is more secure, and the information stored in keychain is not lost because the App is deleted. Therefore, after you reinstall the App, data in the keychain can also be used. From ios 3. Starts from 0, and cross-program keychain sharing becomes feasible.
SSKeyChains encapsulates Apple's security framework APIs and supports access to passwords and Accounts stored in Key Strings, including reading, deleting, and setting. The author of SSKeyChain is samsoffes, the famous SSToolkit.
Project address: https://github.com/samsoffes/sskeychain
Add SSKeyChain to the Project
- Add the Security. framework to the project.
- Add SSKeychain. h and SSKeychain. m to the project folder.
Use SSKeyChain
Use SSKeyChain using the following methods (see SSKeyChain. h ):
+ (NSArray *) allAccounts;
+ (NSArray *) accountsForService :( NSString *) serviceName;
+ (NSString *) passwordForService :( NSString *) serviceNameaccount :( NSString *) account;
+ (BOOL) deletePasswordForService :( NSString *) serviceNameaccount :( NSString *) account;
+ (BOOL) setPassword :( NSString *) password forService :( NSString *) serviceName account :( NSString *) account;
Document
To install SSKeyChain in Xcode, follow these steps:
- Choose Xcode> Preferences.
- Select Downloads
- Select Documentation
- Click the plus sign at the bottom and enter the following URL: http://docs.samsoff.es/com.samsoffes.sskeychain.atom
- Click the install button next to "SSKeyChain Documentation. (If you do not see it and no error is prompted, restart Xcode)
Make sure that SSKeychain is visible in the optional docset in Organizer.
In addition, you can viewSSKeychain Documentation.
Debugging
If the key string cannot be saved, use the error code provided in SSKeychain. h, for example:
NSError * error = nil;
NSString * password = [SSKeychainpasswordForService: @ "MyService" account: @ "samsoffes" error: & error];
If ([error code] = SSKeychainErrorNotFound ){
NSLog (@ "Passwordnot found ");
}
Obviously, you should be familiar with this. Access to the key string is a pain point, and you need to check every error or failure at any time. SSKeychain does not make it (key string) more stable. It is just a tedious C APIs encapsulation.
Sample Code
Save a UUID string to the key string:
CFUUIDRef uuid = CFUUIDCreate(NULL);assert(uuid != NULL);CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid);
[SSKeychain setPassword: [NSString stringWithFormat:@"%@", uuidStr]
ForService: @ "com. yourapp. yourcompany" account: @ "user"];
Then, read the UUID from the key string:
NSString * retrieveuuid = [SSKeychainpasswordForService: @ "com. yourapp. yourcompany" account: @ "user"];
Note: In the setPassword and passwordForSevice methods
Services and accounts parameters should be consistent.
What is the unique ID of the data stored on the website?
ID is the abbreviation of IDentity. It is also called the serial number or account number. It is a relatively unique encoding in a system. It is equivalent to an "ID Card". In a specific thing, the ID number is generally unchanged, as to what is used to identify a thing, it is determined by the rules set by the designer.
The ID can be the user name and password of your QQ account, online Logon account, and various social and information websites. It can be random or fixed.
The unique ID of the data stored on the website. I understand that some data on the website can only be stored on the physical address of the computer.
Analyze the specific situation.
If you have other questions, follow these questions. I hope it will help you and hope to adopt it.
How to save the user name and password for ios development
Upload the server to save .. Save the local plist .. Save Userdefault .. Sqlite save