How do I use Apple Keychain?
Asked Answered
Z

1

26

I am using trying to use scifihifi-iphone (from Github) to store and retrieve usernames and passwords. However, when I add the class SFHFKeychainUtils I get the following errors:

  "_kSecAttrAccount", referenced from:
      _kSecAttrAccount$non_lazy_ptr in SFHFKeychainUtils.o
  "_SecItemDelete", referenced from:
      +[SFHFKeychainUtils deleteItemForUsername:andServiceName:error:] in SFHFKeychainUtils.o
  "_kSecReturnAttributes", referenced from:
      _kSecReturnAttributes$non_lazy_ptr in SFHFKeychainUtils.o
  "_kSecClass", referenced from:
      _kSecClass$non_lazy_ptr in SFHFKeychainUtils.o
  "_kSecClassGenericPassword", referenced from:
      _kSecClassGenericPassword$non_lazy_ptr in SFHFKeychainUtils.o
  "_SecItemAdd", referenced from:
      +[SFHFKeychainUtils storeUsername:andPassword:forServiceName:updateExisting:error:] in SFHFKeychainUtils.o
  "_kSecAttrLabel", referenced from:
      _kSecAttrLabel$non_lazy_ptr in SFHFKeychainUtils.o
  "_SecItemUpdate", referenced from:
      +[SFHFKeychainUtils storeUsername:andPassword:forServiceName:updateExisting:error:] in SFHFKeychainUtils.o
  "_kSecAttrService", referenced from:
      _kSecAttrService$non_lazy_ptr in SFHFKeychainUtils.o
  "_kSecReturnData", referenced from:
      _kSecReturnData$non_lazy_ptr in SFHFKeychainUtils.o
  "_SecItemCopyMatching", referenced from:
      +[SFHFKeychainUtils getPasswordForUsername:andServiceName:error:] in SFHFKeychainUtils.o
      +[SFHFKeychainUtils getPasswordForUsername:andServiceName:error:] in SFHFKeychainUtils.o
  "_kSecValueData", referenced from:
      _kSecValueData$non_lazy_ptr in SFHFKeychainUtils.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

What am I leaving out? When I click the errors, it doesn't take me to any place in the code.

Zygophyte answered 12/10, 2009 at 14:38 Comment(3)
It looks like a linker error. Is this the first time your code has done anything with Keychain?Soricine
Did you add the Keychain framework too?Zachary
How do I add the Keychain framework to my app?Zygophyte
K
76

Add Security.framework, then rebuild. Sometimes I find I have to build clean and then rebuild.

To add this, right click on your target in Xcode, then Add->Existing Frameworks and choose (or navigate) to Security.framework.

Kielty answered 12/10, 2009 at 15:58 Comment(2)
Thanks, that's great. I was looking for a framework called Keychain.framework which obviously doesn't exist.Zygophyte
That solved my problem BUT I had to drag Security.framework into the project from Finder, adding it in the XCode 4.2 "link with libraries" section did not work (it didn't seem to find the framework it had added).Bagdad

© 2022 - 2024 — McMap. All rights reserved.