iOS App Extension implementation
You can use supported Adobe Experience Platform mobile extensions in your App Extensions to collect usage data. The supported Platform 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.
- In the Podfile, add a new target for your app extension and include the Adobe pods:
Copied to your clipboardtarget 'YourApp' dopod 'AEPServices'pod 'AEPCore'pod 'AEPLifecycle'pod 'AEPIdentity'pod 'AEPAnalytics'endtarget 'YourAppExtension' dopod 'AEPServices'pod 'AEPCore'pod 'AEPLifecycle'pod 'AEPIdentity'pod 'AEPAnalytics'end
- 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.
- Make sure that your
ShareViewController
has the proper imports for the SDK.
Copied to your clipboardimport UIKitimport Socialimport AEPCoreimport AEPIdentityimport AEPAnalyticsimport AEPLifecycle
- Register the SDK in the
ShareViewController
'spresentationAnimationDidFinish
method:
Swift
Copied to your clipboardoverride func presentationAnimationDidFinish() {MobileCore.registerExtensions([Identity.self, Lifecycle.self, AnalyticsAppExtension.self], {MobileCore.configureWith(appId: "your-app-id")MobileCore.lifecycleStart(additionalContextData: nil)})}
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.
- Managing lifecycle from a Share Extension should be done in the
didSelectCancel
anddidSelectPost
methods which are the delegate methods called when the ShareViewController is dismissed.
Swift
Copied to your clipboardoverride func didSelectCancel() {MobileCore.lifecyclePause()}override func didSelectPost() {MobileCore.lifecyclePause()...}
You are now ready to use the SDK in your App Extension.