Sharing Keychain Access Storage Between iOS app and Widget

If you want to add the widget to your existing iOS app and have access to the storage, you are in the right place. I will quickly show you how below.

First of all, you will need to add Keychain Group and App Group in both your app and widget target’s Build Settings under Signing & Capabilities. If you want to know their differences, you can read up on this documentation by Apple. Moreover, naming them can be based on your app bundle identifier. Here is an example:

  • App Bundle Identifier:
  • App Group:
  • Keychain Group:

Then, you can start to integrate the app group and keychain group into your code. In this example, I am going to use a third-party library called KeychainAccess to interact with the keychain access. Here is my sample code:

You can add both your app and your widget to the file’s Target Membership so that they can both use it to save and load from the keychain storage.

Leave a Comment

Your email address will not be published. Required fields are marked *