matthewpalmer / Locksmith

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

Not working with app extension #174

Open andymedvedev opened 7 years ago

andymedvedev commented 7 years ago

I have created Action extension for the app. In app i set the field and then i want to retrieve them in extension but its failed (dictionary not found).

dannymout commented 7 years ago

To solve your issue, we might need to see your code. All I can say right now, is that you probably incorrectly spelt forUserAccount:, causing the dictionary not to be found.

shuhrat10 commented 7 years ago

@andertsk

When you trying to get value from Keychain in your extension, you have to do this way:

let value = Locksmith.loadDataForUserAccount(userAccount: "user_account", inService: "__YOUR__APP_BUNDLE_ID____") Usually you have different bundle ID for app and extension. For example:

Application bundle id: com.mywebsite.myapp Extension bundle id: com.mywebsite.myapp.extension

If you try to get value without passing inService value. Like that:

let value = Locksmith.loadDataForUserAccount(userAccount: "user_account")

Locksmith will not return value, because it will use Bundle ID of the Extension. But your value has been saved under your app bundle id.

You also need to make sure, you are enable keychain share under Project -> Capabilities for app and extension target. And they both use the same group.

andymedvedev commented 7 years ago

@shuhrat10 thanks! You solve my problem!