iOS App Extension implementation
You can use supported Adobe Experience Platform mobile extensions in your App Extensions to collect usage data. The supported AEP mobile extensions are listed here.

Prerequisites

  • This tutorial assumes a basic understanding of how to use the iOS AEP Mobile SDK in applications. For more details see Getting Started.
  • You should have CocoaPods installed.

Adding the AEP mobile extensions

Adding the Mobile SDK to your App Extension works the same way as adding the Mobile SDK to your application.
  1. 1.
    In the Podfile, add a new target for your app extension and include the Adobe pods:
1
target 'YourApp' do
2
pod 'AEPServices'
3
pod 'AEPCore'
4
pod 'AEPLifecycle'
5
pod 'AEPIdentity'
6
pod 'AEPAnalytics'
7
end
8
9
target 'YourAppExtension' do
10
pod 'AEPServices'
11
pod 'AEPCore'
12
pod 'AEPLifecycle'
13
pod 'AEPIdentity'
14
pod 'AEPAnalytics'
15
end
Copied!
  1. 1.
    Run pod install from the command line to install the pods to the App Extension target.

Registering Extensions

This tutorial uses the ShareExtension as the example.
Depending on the type of App Extension you are using, the registration and usage of the SDK will look different. Make sure you understand the lifecycle of your App Extension in order to know where best to register the SDK and call lifecycle start/pause.
  1. 1.
    Make sure that your ShareViewController has the proper imports for the SDK.
1
import UIKit
2
import Social
3
import AEPCore
4
import AEPIdentity
5
import AEPAnalytics
6
import AEPLifecycle
Copied!
  1. 1.
    Register the SDK in the ShareViewController's presentationAnimationDidFinish method:

Swift

1
override func presentationAnimationDidFinish() {
2
MobileCore.registerExtensions([Identity.self, Lifecycle.self, AnalyticsAppExtension.self], {
3
MobileCore.configureWith(appId: "your-app-id")
4
MobileCore.lifecycleStart(additionalContextData: nil)
5
})
6
}
Copied!
Please note that in order to register AEPAnalytics, you must use the AnalyticsAppExtension class instead of the Analytics class used when registering from an application.
  1. 1.
    Managing lifeycle from a Share Extension should be done in the didSelectCancel and didSelectPost methods which are the delegate methods called when the ShareViewController is dismissed.

Swift

1
override func didSelectCancel() {
2
MobileCore.lifecyclePause()
3
}
4
5
override func didSelectPost() {
6
MobileCore.lifecyclePause()
7
...
8
}
Copied!
You are now ready to use the SDK in your App Extension.