[IOS] saves the unique ID of the user and the id of the ios storage.

Source: Internet
Author: User

[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

  1. Add the Security. framework to the project.
  2. 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:

  1. Choose Xcode> Preferences.
  2. Select Downloads
  3. Select Documentation
  4. Click the plus sign at the bottom and enter the following URL: http://docs.samsoff.es/com.samsoffes.sskeychain.atom
  5. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.