# iOS app extension integration

iOS app extensions can be developed in both Swift and Objective-C.&#x20;

Appfigurate Library works in most types of iOS app extensions.

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

You must perform the following before starting iOS app extension integration:

* [iOS native app integration](https://docs.electricbolt.co.nz/getting-started/ios-native-app-integration) of Appfigurate Library.

## Add AppfigurateLibrary.xcframework to the iOS app extension target

In Xcode, tap on your iOS app extension target.

Tap the `General` tab. Tap the `+` button under the `Frameworks, Libraries` section.

Select `AppfigurateLibrary` package.

## Share the iOS app APLConfiguration subclass with the iOS app extension

Share the iOS app's [<mark style="color:blue;">`APLConfiguration`</mark>](https://www.electricbolt.co.nz/api/Classes/APLConfiguration.html) subclass with the iOS app extension.&#x20;

Open your [<mark style="color:blue;">`APLConfiguration`</mark>](https://www.electricbolt.co.nz/api/Classes/APLConfiguration.html) subclass (e.g. `Configuration.swift/m` file) into the Xcode editor.&#x20;

In the `Target Membership` inspection pane tick on your iOS app extension target.

## **Setup Keychain Sharing in the iOS app extension**

Tap on your iOS app extension target.

Tap the `Signing & Capabilities` tabs. Add a `Keychain Sharing` capability with a `Keychain Groups` value that will be common across the iOS app and iOS app extension.&#x20;

We recommend you have a `.shared` suffix on *your* Keychain Groups value.

<figure><img src="https://1008176080-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fw1fcw3dvtSrfUh3YtO9Z%2Fuploads%2FaST2bn00olk7MxhMbfmW%2FKeychainSharing.png?alt=media&#x26;token=66954bf0-6f18-4778-9752-5a278f922958" alt=""><figcaption></figcaption></figure>

## **Setup Keychain Sharing in the iOS app**

Tap on your iOS app target.&#x20;

Tap `Signing & Capabilities` tabs.&#x20;

Add a `Keychain Sharing` capability with the same `Keychain Groups` value you entered for the iOS app extension above.

<figure><img src="https://1008176080-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fw1fcw3dvtSrfUh3YtO9Z%2Fuploads%2F5Wiro44TqlL0KhXWR40p%2Fimage.png?alt=media&#x26;token=79d0f29a-fc1a-41ac-9fa3-7904b8dd8bd7" alt=""><figcaption></figcaption></figure>

## Edit Info.plist in the iOS app

In your iOS app's `Info.plist` file (right click, `Open As` ‣ `Source Code`) include the `APLKeychainAccessGroup` key replacing the value `nz.co.electricbolt.appfigurateexample.shared` with *your* `Keychain Sharing`'s `Keychain Groups` value.

> `Info.plist` example

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
     <key>APLKeychainAccessGroup</key>
     <string>nz.co.electricbolt.appfigurateexample.shared</string>
     ...
```

{% hint style="warning" %}
If the `APLKeychainAccessGroup` key is not defined, then keychain access group functionality is not used. Do not specify an empty or otherwise invalid `APLKeychainAccessGroup` value.
{% endhint %}

{% hint style="success" %}
iOS app extensions automatically use the `Info.plist` file from the containing iOS app. You do not need to modify the iOS app extension's `Info.plist` file.
{% endhint %}

## Test your iOS app extension

To test that you've successfully updated your iOS app extension to use Appfigurate:

* Compile and run your app to the Simulator instance.
* Launch the Appfigurate Simulator app.
* Tap your applications row. The app will be run and made visible, it's configuration read, and then swap back to Appfigurate.
* Appfigurate's [Configure app](https://docs.electricbolt.co.nz/appfigurate-user-guide/configure-app) screen will now be displayed. You can now change the `debugLogging` and `serverURL` properties. Tap `Apply⌄` to apply the configuration to your app.
* Invoke your app extension. It should be using the shared configuration applied to the app.
