matthewpalmer / Locksmith

A powerful, protocol-oriented library for working with the keychain in Swift.
MIT License
2.92k stars 266 forks source link

Keychain Sharing not working between two apps? #196

Open RPiyush opened 6 years ago

RPiyush commented 6 years ago

Hi have to share keychain between my two apps, for this I have tried following with Locksmith:

  1. Enable Keychain sharing in capabilities.
  2. Added common group name TestKeychainGroup.
  3. Saved my data with Key MyteamID.TestKeychainGroup. It saved success
  4. Now when i tries to retrieve saved data from keychain with key MyteamID.TestKeychainGroup it is giving nil.

Can anybody tell me, what I forgot to do or it is not supported by Locksmith. Thanks

tosbaha commented 5 years ago

If you are using default LockSmith setup then your service is setup with this code

public let LocksmithDefaultService = Bundle.main.infoDictionary![String(kCFBundleIdentifierKey)] as? String ?? "com.locksmith.defaultService"

It means it is getting the service name from kCFBundleIdentifierKey which is different for every app and extension. You must set it to same value either editing the source code of LockSmith.swift or using long notation by explicitly setting the service in the function calls. I also made the same mistake and wasted an hour lol