Lifecycle
This document lists information about the previous versions of the Adobe Experience Platform Mobile SDKs. Check out this page for latest versions and solution support of the Mobile SDKs.
In version 4 of the iOS SDK, this implementation was completed automatically.
The Experience Platform SDK will not automatically collect Lifecycle metrics. To continue collecting Lifecycle metrics, you must add code to your app. For more information, see Manual Lifecycle Implementation.
Sessions contain information about the app's current lifecycle, such as the device information, the application install or upgrade information, the session start and pause times, the number of application launches, and additional context data that is provided by the developer through the LifecycleStart
API. Session data is persisted, so it is available across application launches.
Add Lifecycle to your app
Import the library:
Copied to your clipboardimport com.adobe.marketing.mobile.*;
The Lifecycle extension is included in the Mobile Core extension. Add the Mobile Core extension to your project using Cocoapods.
Add the following pod in your Podfile
:
Copied to your clipboardpod 'ACPCore','~>2.0'
Import the Lifecycle library:
Swift
In Swift, importing ACPCore
also imports the necessary Lifecycle APIs:
Copied to your clipboardimport ACPCore
Objective-C
Copied to your clipboard#import "ACPLifecycle.h"#import "ACPCore.h"
C#
After importing the ACPCore.unitypackage, the Lifecycle extension for Unity can be added with following code in the MainScript
Copied to your clipboardusing com.adobe.marketing.mobile;
Import the library:
Copied to your clipboardimport com.adobe.marketing.mobile.*;
The Lifecycle extension is included in the Mobile Core extension. Add the Mobile Core extension to your project using Cocoapods.
Add the following pod in your Podfile
:
Copied to your clipboardpod 'ACPCore','~>2.0'
Import the Lifecycle library:
Swift
In Swift, importing ACPCore
also imports the necessary Lifecycle APIs:
Copied to your clipboardimport ACPCore
Objective-C
Copied to your clipboard#import "ACPLifecycle.h"#import "ACPCore.h"
JavaScript
Import the Lifecycle extension
Copied to your clipboardimport {ACPLifecycle} from '@adobe/react-native-acpcore';
Dart
Import the Lifecycle extension
Copied to your clipboardimport 'package:flutter_acpcore/flutter_acplifecycle.dart';
Cordova
After creating your Cordova app and adding the Android and iOS platforms, the Lifecycle extension for Cordova can be added with this command:
Copied to your clipboardcordova plugin add https://github.com/adobe/cordova-acpcore.git
C#
After importing the ACPCore.unitypackage, the Lifecycle extension for Unity can be added with following code in the MainScript
Copied to your clipboardusing com.adobe.marketing.mobile;
Register Lifecycle with Mobile Core and add appropriate Start/Pause calls
- Register the Lifecycle extension:
Copied to your clipboardpublic class TargetApp extends Application {@Overridepublic void onCreate() {super.onCreate();MobileCore.setApplication(this);try {Lifecycle.registerExtension();// register other extensionsMobileCore.start(new AdobeCallback () {@Overridepublic void call(Object o) {MobileCore.configureWithAppID("yourAppId");}});} catch (Exception e) {//Log the exception}}}
- In the
onResume
function, start the lifecycle data collection:
Copied to your clipboard@Overridepublic void onResume() {MobileCore.setApplication(getApplication());MobileCore.lifecycleStart(null);}
Setting the application is only necessary on activities that are entry points for your application. However, setting the application on each Activity has no negative impact and ensures that the SDK always has the necessary reference to your application. We recommend that you call setApplication
in each of your activities.
- In the
onPause
function, pause the lifecycle data collection:
Copied to your clipboard@Overridepublic void onPause() {MobileCore.lifecyclePause();}
To ensure accurate session and crash reporting, this call must be added to every activity.
Swift
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method:
Copied to your clipboardfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// register the lifecycle extensionACPLifecycle.registerExtension();}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theACPCore::start:
method in your app'sapplication:didFinishLaunchingWithOptions:
delegate method.
If your iOS application supports background capabilities, your application:didFinishLaunchingWithOptions:
method might be called when iOS launches your app in the background. If you do not want background launches to count towards your lifecycle metrics, then lifecycleStart:
should only be called when the application state is not equal to UIApplicationStateBackground
.
Copied to your clipboardfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {// register the lifecycle extensionACPLifecycle.registerExtension();let appState = application.applicationState;ACPCore.start {// only start lifecycle if the application is not in the backgroundif appState != .background {ACPCore.lifecycleStart(nil)}}}
- When launched, if your app is resuming from a backgrounded state, iOS might call your
applicationWillEnterForeground:
delegate method. You also need to calllifecycleStart:
, but this time you do not need all of the supporting code that you used inapplication:didFinishLaunchingWithOptions:
:
Copied to your clipboardfunc applicationWillEnterForeground(_ application: UIApplication) {ACPCore.lifecycleStart(nil)}
In iOS 13 and later, for a scene-based application, use the UISceneDelegate
's sceneWillEnterForeground
method as follows:
Copied to your clipboardfunc sceneWillEnterForeground(_ scene: UIScene) {ACPCore.lifecycleStart(nil)}
For more information on handling foregrounding applications with Scenes, refer to Apple's documentation here
- When the app enters the background, pause Lifecycle data collection from your app's
applicationDidEnterBackground:
delegate method:
Copied to your clipboardfunc applicationDidEnterBackground(_ application: UIApplication) {ACPCore.lifecyclePause()}
In iOS 13 and later, for a scene-based application, use the UISceneDelegate
's sceneDidEnterBackground
method as follows:
Copied to your clipboardfunc sceneDidEnterBackground(_ scene: UIScene) {ACPCore.lifecyclePause()}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Objective-C
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method:
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[ACPLifecycle registerExtension];return YES;}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theACPCore::start:
method in your app'sapplication:didFinishLaunchingWithOptions:
delegate method.
If your iOS application supports background capabilities, your application:didFinishLaunchingWithOptions:
method might be called when iOS launches your app in the background. If you do not want background launches to count towards your lifecycle metrics, then lifecycleStart:
should only be called when the application state is not equal to UIApplicationStateBackground
.
Copied to your clipboard- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[ACPLifecycle registerExtension];const UIApplicationState appState = application.applicationState;[ACPCore start:^{// only start lifecycle if the application is not in the backgroundif (appState != UIApplicationStateBackground) {[ACPCore lifecycleStart:nil];}}];}
- When launched, if your app is resuming from a backgrounded state, iOS might call your
applicationWillEnterForeground:
delegate method. You also need to calllifecycleStart:
, but this time you do not need all of the supporting code that you used inapplication:didFinishLaunchingWithOptions:
:
Copied to your clipboard- (void) applicationWillEnterForeground:(UIApplication *)application {[ACPCore lifecycleStart:nil];}
In iOS 13 and later, for a scene-based application, use the UISceneDelegate
's sceneWillEnterForeground
method as follows:
Copied to your clipboard- (void) sceneWillEnterForeground:(UIScene *)scene {[ACPCore lifecycleStart:nil];}
For more information on handling foregrounding applications with Scenes, refer to Apple's documentation here
- When the app enters the background, pause Lifecycle data collection from your app's
applicationDidEnterBackground:
delegate method:
Copied to your clipboard- (void) applicationDidEnterBackground:(UIApplication *)application {[ACPCore lifecyclePause];}
In iOS 13 and later, for a scene-based application, use the UISceneDelegate
's sceneDidEnterBackground
method as follows:
Copied to your clipboard- (void) sceneDidEnterBackground:(UIScene *)scene {[ACPCore lifecyclePause];}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Registering the extension with Core
When using React Native, registering Lifecycle with Mobile Core should be done in native code which is shown under the Android and iOS (ACP 2.x) tabs.
When using Cordova, registering Lifecycle with Mobile Core must be done in native code which is shown under the Android and iOS tabs.
Starting and Pausing a lifecycle event
Add the OnApplicationPause in the MainScript with the following code:
Copied to your clipboardprivate void OnApplicationPause(bool pauseStatus){if (pauseStatus){ACPCore.LifecyclePause();}else{var cdata = new Dictionary<string, string>();cdata.Add("launch.data", "added");ACPCore.LifecycleStart(cdata);}}
iOS
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
FinishedLaunching:
delegate method:
Copied to your clipboardpublic override bool FinishedLaunching(UIApplication app, NSDictionary options){ACPLifecycle.RegisterExtension();return base.FinishedLaunching(app, options);}
- Start Lifecycle data collection by calling
LifecycleStart:
from within the callback of theACPCore::start:
method in your app'sFinishedLaunching:
delegate method.
If your iOS application supports background capabilities, your FinishedLaunching:
method might be called when iOS launches your app in the background. If you do not want background launches to count towards your lifecycle metrics, then LifecycleStart:
should only be called when the application state is not equal to UIApplicationState.Background
.
Copied to your clipboardpublic override bool FinishedLaunching(UIApplication app, NSDictionary options){ACPLifecycle.RegisterExtension();// only start lifecycle if the application is not in the backgroundvar appstate = app.ApplicationState;if(appstate != UIApplicationState.Background){ACPCore.LifecycleStart(null);}return base.FinishedLaunching(app, options);}
- When launched, if your app is resuming from a backgrounded state, iOS might call your
WillEnterForeground:
delegate method. You also need to callLifecycleStart:
, but this time you do not need all of the supporting code that you used inFinishedLaunching:
:
Copied to your clipboardpublic override void WillEnterForeground(UIApplication uiApplication){base.WillEnterForeground(uiApplication);ACPCore.LifecycleStart(null);}
- When the app enters the background, pause Lifecycle data collection from your app's
DidEnterBackground:
delegate method:
Copied to your clipboardpublic override void DidEnterBackground(UIApplication uiApplication){base.DidEnterBackground(uiApplication);ACPCore.LifecyclePause();}
Android
- Register the Lifecycle extension:
Copied to your clipboardprotected override void OnCreate(Bundle savedInstanceState){base.OnCreate(savedInstanceState);LoadApplication(new App());ACPCore.Application = this.Application;ACPLifecycle.RegisterExtension();}
- In the
onResume
function, start the lifecycle data collection:
Copied to your clipboardprotected override void OnResume(){base.OnResume();ACPCore.LifecycleStart(null);}
Setting the application is only necessary on activities that are entry points for your application. However, setting the application on each Activity has no negative impact and ensures that the SDK always has the necessary reference to your application. You should set the application (ACPCore.Application = this.Application;
) in each of your activities.
- In the
onPause
function, pause the lifecycle data collection:
Copied to your clipboardprotected override void OnPause(){base.OnPause();ACPCore.LifecyclePause();}
To ensure accurate session and crash reporting, this call must be added to every activity.
- Register the Lifecycle extension:
Copied to your clipboardpublic class TargetApp extends Application {@Overridepublic void onCreate() {super.onCreate();MobileCore.setApplication(this);try {Lifecycle.registerExtension();// register other extensionsMobileCore.start(new AdobeCallback () {@Overridepublic void call(Object o) {MobileCore.configureWithAppID("yourAppId");}});} catch (Exception e) {//Log the exception}}}
- In the
onResume
function, start the lifecycle data collection:
Copied to your clipboard@Overridepublic void onResume() {MobileCore.setApplication(getApplication());MobileCore.lifecycleStart(null);}
Setting the application is only necessary on activities that are entry points for your application. However, setting the application on each Activity has no negative impact and ensures that the SDK always has the necessary reference to your application. We recommend that you call setApplication
in each of your activities.
- In the
onPause
function, pause the lifecycle data collection:
Copied to your clipboard@Overridepublic void onPause() {MobileCore.lifecyclePause();}
To ensure accurate session and crash reporting, this call must be added to every activity.
Swift
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method:
Copied to your clipboardfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// register the lifecycle extensionACPLifecycle.registerExtension();}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theACPCore::start:
method in your app'sapplication:didFinishLaunchingWithOptions:
delegate method.
If your iOS application supports background capabilities, your application:didFinishLaunchingWithOptions:
method might be called when iOS launches your app in the background. If you do not want background launches to count towards your lifecycle metrics, then lifecycleStart:
should only be called when the application state is not equal to UIApplicationStateBackground
.
Copied to your clipboardfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {// register the lifecycle extensionACPLifecycle.registerExtension();let appState = application.applicationState;ACPCore.start {// only start lifecycle if the application is not in the backgroundif appState != .background {ACPCore.lifecycleStart(nil)}}}
- When launched, if your app is resuming from a backgrounded state, iOS might call your
applicationWillEnterForeground:
delegate method. You also need to calllifecycleStart:
, but this time you do not need all of the supporting code that you used inapplication:didFinishLaunchingWithOptions:
:
Copied to your clipboardfunc applicationWillEnterForeground(_ application: UIApplication) {ACPCore.lifecycleStart(nil)}
In iOS 13 and later, for a scene-based application, use the UISceneDelegate
's sceneWillEnterForeground
method as follows:
Copied to your clipboardfunc sceneWillEnterForeground(_ scene: UIScene) {ACPCore.lifecycleStart(nil)}
For more information on handling foregrounding applications with Scenes, refer to Apple's documentation here
- When the app enters the background, pause Lifecycle data collection from your app's
applicationDidEnterBackground:
delegate method:
Copied to your clipboardfunc applicationDidEnterBackground(_ application: UIApplication) {ACPCore.lifecyclePause()}
In iOS 13 and later, for a scene-based application, use the UISceneDelegate
's sceneDidEnterBackground
method as follows:
Copied to your clipboardfunc sceneDidEnterBackground(_ scene: UIScene) {ACPCore.lifecyclePause()}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Objective-C
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method:
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[ACPLifecycle registerExtension];return YES;}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theACPCore::start:
method in your app'sapplication:didFinishLaunchingWithOptions:
delegate method.
If your iOS application supports background capabilities, your application:didFinishLaunchingWithOptions:
method might be called when iOS launches your app in the background. If you do not want background launches to count towards your lifecycle metrics, then lifecycleStart:
should only be called when the application state is not equal to UIApplicationStateBackground
.
Copied to your clipboard- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[ACPLifecycle registerExtension];const UIApplicationState appState = application.applicationState;[ACPCore start:^{// only start lifecycle if the application is not in the backgroundif (appState != UIApplicationStateBackground) {[ACPCore lifecycleStart:nil];}}];}
- When launched, if your app is resuming from a backgrounded state, iOS might call your
applicationWillEnterForeground:
delegate method. You also need to calllifecycleStart:
, but this time you do not need all of the supporting code that you used inapplication:didFinishLaunchingWithOptions:
:
Copied to your clipboard- (void) applicationWillEnterForeground:(UIApplication *)application {[ACPCore lifecycleStart:nil];}
In iOS 13 and later, for a scene-based application, use the UISceneDelegate
's sceneWillEnterForeground
method as follows:
Copied to your clipboard- (void) sceneWillEnterForeground:(UIScene *)scene {[ACPCore lifecycleStart:nil];}
For more information on handling foregrounding applications with Scenes, refer to Apple's documentation here
- When the app enters the background, pause Lifecycle data collection from your app's
applicationDidEnterBackground:
delegate method:
Copied to your clipboard- (void) applicationDidEnterBackground:(UIApplication *)application {[ACPCore lifecyclePause];}
In iOS 13 and later, for a scene-based application, use the UISceneDelegate
's sceneDidEnterBackground
method as follows:
Copied to your clipboard- (void) sceneDidEnterBackground:(UIScene *)scene {[ACPCore lifecyclePause];}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Registering the extension with Core
When using React Native, registering Lifecycle with Mobile Core should be done in native code which is shown under the Android and iOS (ACP 2.x) tabs.
When using Cordova, registering Lifecycle with Mobile Core must be done in native code which is shown under the Android and iOS tabs.
Starting and Pausing a lifecycle event
Add the OnApplicationPause in the MainScript with the following code:
Copied to your clipboardprivate void OnApplicationPause(bool pauseStatus){if (pauseStatus){ACPCore.LifecyclePause();}else{var cdata = new Dictionary<string, string>();cdata.Add("launch.data", "added");ACPCore.LifecycleStart(cdata);}}
iOS
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
FinishedLaunching:
delegate method:
Copied to your clipboardpublic override bool FinishedLaunching(UIApplication app, NSDictionary options){ACPLifecycle.RegisterExtension();return base.FinishedLaunching(app, options);}
- Start Lifecycle data collection by calling
LifecycleStart:
from within the callback of theACPCore::start:
method in your app'sFinishedLaunching:
delegate method.
If your iOS application supports background capabilities, your FinishedLaunching:
method might be called when iOS launches your app in the background. If you do not want background launches to count towards your lifecycle metrics, then LifecycleStart:
should only be called when the application state is not equal to UIApplicationState.Background
.
Copied to your clipboardpublic override bool FinishedLaunching(UIApplication app, NSDictionary options){ACPLifecycle.RegisterExtension();// only start lifecycle if the application is not in the backgroundvar appstate = app.ApplicationState;if(appstate != UIApplicationState.Background){ACPCore.LifecycleStart(null);}return base.FinishedLaunching(app, options);}
- When launched, if your app is resuming from a backgrounded state, iOS might call your
WillEnterForeground:
delegate method. You also need to callLifecycleStart:
, but this time you do not need all of the supporting code that you used inFinishedLaunching:
:
Copied to your clipboardpublic override void WillEnterForeground(UIApplication uiApplication){base.WillEnterForeground(uiApplication);ACPCore.LifecycleStart(null);}
- When the app enters the background, pause Lifecycle data collection from your app's
DidEnterBackground:
delegate method:
Copied to your clipboardpublic override void DidEnterBackground(UIApplication uiApplication){base.DidEnterBackground(uiApplication);ACPCore.LifecyclePause();}
Android
- Register the Lifecycle extension:
Copied to your clipboardprotected override void OnCreate(Bundle savedInstanceState){base.OnCreate(savedInstanceState);LoadApplication(new App());ACPCore.Application = this.Application;ACPLifecycle.RegisterExtension();}
- In the
onResume
function, start the lifecycle data collection:
Copied to your clipboardprotected override void OnResume(){base.OnResume();ACPCore.LifecycleStart(null);}
Setting the application is only necessary on activities that are entry points for your application. However, setting the application on each Activity has no negative impact and ensures that the SDK always has the necessary reference to your application. You should set the application (ACPCore.Application = this.Application;
) in each of your activities.
- In the
onPause
function, pause the lifecycle data collection:
Copied to your clipboardprotected override void OnPause(){base.OnPause();ACPCore.LifecyclePause();}
To ensure accurate session and crash reporting, this call must be added to every activity.
Lifecycle metrics
Please refer to the Metrics documentation to view the full list of lifecycle metrics.