11

I'm trying to figure out how to use the SSkeychain in order to store access tokens for the instagram api. I'm currently using NSUserDefault class but I dont think thats the best of ideas.

Does the SSkeychain class itself need to be allocated and initialized in order to be used as well?

TheM00s3
  • 3,677
  • 4
  • 31
  • 65

1 Answers1

28

SSKeychain just provides class methods, so you don't need to initialize an instance. It does require some setup, though. The readme is a great source of information on this.

Here's a code example to help:

// Specify how the keychain items can be access
// Do this in your -application:didFinishLaunchingWithOptions: callback
[SSKeychain setAccessibilityType:kSecAttrAccessibleWhenUnlocked];

// Set an access token for later use
[SSKeychain setPassword:instagramToken forService:@"InstagramService" account:@"com.yourapp.keychain"];

// Access that token when needed
[SSKeychain passwordForService:@"InstagramService" account:@"com.yourapp.keychain"];

// Delete the token when appropriate (on sign out, perhaps)
[SSKeychain deletePasswordForService:@"InstagramService" account:@"com.yourapp.keychain"];

I'd also recommend making those @"InstagramService" and @"com.yourapp.keychain" strings constants so it's easier to reference them.

Hope that helps!

Stephen C
  • 455
  • 5
  • 10
  • 5
    The SSKeychain is now deprecated and you need to use SamKeyChain instead.See https://github.com/soffes/samkeychain – shah1988 Aug 25 '16 at 11:07
  • 2
    @shah1988 Its still the same wrapper, just a new name because of a clash with one of Apples classes. – pnizzle Jun 07 '17 at 07:36