For a recent iOS app I was working on, there was a need to integrate the Keychain to save the login credentials locally.
After a bit of searching and fumbling through the internet, I found a great library: SFHFKeychainUtils, originally created by Buzz Andersen. I was so excited knowing I wouldn’t have to learn yet another entire framework by hand, until I noticed that none of the tutorials I was following actually worked!
First, you’ll want to download the SFHFKeychainUtils and import them into your Xcode project. The version I used that is ARC-Supported is here: https://github.com/stoneros/SFHFKeychainUtils
Then you can add the Security.framework to your project. Just go to your Target App and choose Build Phases. Under Link Binary with Libraries, add Security.framework and make sure it is Required.
Finally, in YourViewController.m, add the dependancies to these libraries:
#import <Security/Security.h> #import "SFHFKeychainUtils.h"
Now for the good stuff! Let’s get that keychain working!
Usually, you are just going to be looking for a form submission to grab the credentials, so here’s an easy way of doing that.
Next, in your webViewDidFinishLoad section we need to add some listeners to automatically fill in the saved keychain for the next time, your user needs to login.
This just give you the overall basics, and if it helps you or if you have any questions, just shoot me a comment below!