Debugging and lifecycle metrics
Debug logging
Debug logging is an optional, but a recommended and critical SDK feature.
By enabling logging, you can ensure that the SDK is working as intended. The following table explains levels of logging available and the purpose they serve:
Log Level | Description |
---|---|
Error | This is the default log level used by SDK. This log level provides the details about unrecoverable errors that occurred during SDK implementation. |
Warning | In addition to the details from Error log level, Warning provides error information during SDK integration. This log level might indicate that a request has been made to the SDK, but the SDK might be unable to perform the requested task. For example, this log level might be used when catching an unexpected, but recoverable, exception and printing its message. |
Debug | In addition to the details from the Warning log level, Debug also provides high-level information about how the SDK processes network requests/responses data. |
Verbose | In addition to the details from the Debug level, Verbose provides detailed, low-level information about how the SDK processes database interactions and SDK events. |
Using Debug
or Verbose
log levels may cause performance or security concerns. As a result, it is recommended that you use only Error
or Warning
log levels in production applications.
To enable debug logging, use the following methods:
Java
Copied to your clipboardMobileCore.setLogLevel(LoggingMode.DEBUG);// MobileCore.setLogLevel(LoggingMode.VERBOSE);// MobileCore.setLogLevel(LoggingMode.WARNING);// MobileCore.setLogLevel(LoggingMode.ERROR);
Objective-C
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method. This will register the extension with Core and begin Lifecycle event processing:
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{...}];return YES;}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theAEPMobileCore::registerExtensions:
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, and begin event processing with Coreconst UIApplicationState appState = application.applicationState;[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{// only start lifecycle if the application is not in the backgroundif (appState != UIApplicationStateBackground) {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore lifecyclePause];}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Swift
Copied to your clipboardMobileCore.setLogLevel(.debug)// MobileCore.setLogLevel(.trace)// MobileCore.setLogLevel(.warning)// MobileCore.setLogLevel(.error)
Objective-C
Copied to your clipboard[AEPMobileCore setLogLevel:AEPLogLevelDebug];// [AEPMobileCore setLogLevel:AEPLogLevelTrace];// [AEPMobileCore setLogLevel:AEPLogLevelWarning];// [AEPMobileCore setLogLevel:AEPLogLevelError];
Objective-C
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method. This will register the extension with Core and begin Lifecycle event processing:
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{...}];return YES;}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theAEPMobileCore::registerExtensions:
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, and begin event processing with Coreconst UIApplicationState appState = application.applicationState;[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{// only start lifecycle if the application is not in the backgroundif (appState != UIApplicationStateBackground) {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore lifecyclePause];}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Java
Copied to your clipboardMobileCore.setLogLevel(LoggingMode.DEBUG);// MobileCore.setLogLevel(LoggingMode.VERBOSE);// MobileCore.setLogLevel(LoggingMode.WARNING);// MobileCore.setLogLevel(LoggingMode.ERROR);
Objective-C
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method. This will register the extension with Core and begin Lifecycle event processing:
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{...}];return YES;}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theAEPMobileCore::registerExtensions:
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, and begin event processing with Coreconst UIApplicationState appState = application.applicationState;[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{// only start lifecycle if the application is not in the backgroundif (appState != UIApplicationStateBackground) {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore lifecyclePause];}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Swift
Copied to your clipboardMobileCore.setLogLevel(.debug)// MobileCore.setLogLevel(.trace)// MobileCore.setLogLevel(.warning)// MobileCore.setLogLevel(.error)
Objective-C
Copied to your clipboard[AEPMobileCore setLogLevel:AEPLogLevelDebug];// [AEPMobileCore setLogLevel:AEPLogLevelTrace];// [AEPMobileCore setLogLevel:AEPLogLevelWarning];// [AEPMobileCore setLogLevel:AEPLogLevelError];
Objective-C
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method. This will register the extension with Core and begin Lifecycle event processing:
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{...}];return YES;}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theAEPMobileCore::registerExtensions:
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, and begin event processing with Coreconst UIApplicationState appState = application.applicationState;[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{// only start lifecycle if the application is not in the backgroundif (appState != UIApplicationStateBackground) {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore lifecyclePause];}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Lifecycle metrics
Lifecycle metrics are an optional, but valuable feature provided by the Adobe Experience Platform SDK. It provides out-of-the-box, application lifecycle information about your app user. A complete list of available metrics is provided in the lifecycle documentation.
These metrics contain information on the app user's engagement lifecycle such as device information, install or upgrade information, and session start and pause times. You may also set additional lifecycle metrics.
This section shows you how to collect lifecycle metrics. To view, and report on this data in those respective solutions, you need to set up Adobe Analytics or other Experience Cloud solution extensions.
Lifecycle metrics are now available for Edge Network implementations. For more details about the XDM-based lifecycle metrics, see Lifecycle for Edge Network.
Java
With the onResume
function, start 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. As a result, you should call setApplication
on each of your activities.
You can use the onPause
function to pause the lifecycle data collection:
To ensure accurate session and crash reporting, this call must be added to every Activity
.
Copied to your clipboard@Overridepublic void onPause() {MobileCore.lifecyclePause();}
Objective-C
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method. This will register the extension with Core and begin Lifecycle event processing:
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{...}];return YES;}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theAEPMobileCore::registerExtensions:
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, and begin event processing with Coreconst UIApplicationState appState = application.applicationState;[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{// only start lifecycle if the application is not in the backgroundif (appState != UIApplicationStateBackground) {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore lifecyclePause];}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Swift
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method. This will register the extension with Core and begin Lifecycle event processing:
Copied to your clipboardfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {MobileCore.registerExtensions([Lifecycle.self, ...], {...}}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theMobileCore.registerExtensions
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 {let appState = application.applicationStateMobileCore.registerExtensions([Lifecycle.self, ...], {if appState != .background {// only start lifecycle if the application is not in the backgroundMobileCore.lifecycleStart(additionalContextData: 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) {MobileCore.lifecycleStart(additionalContextData: 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) {MobileCore.lifecycleStart(additionalContextData: 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) {MobileCore.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) {MobileCore.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. This will register the extension with Core and begin Lifecycle event processing:
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{...}];return YES;}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theAEPMobileCore::registerExtensions:
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, and begin event processing with Coreconst UIApplicationState appState = application.applicationState;[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{// only start lifecycle if the application is not in the backgroundif (appState != UIApplicationStateBackground) {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore lifecyclePause];}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Java
With the onResume
function, start 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. As a result, you should call setApplication
on each of your activities.
You can use the onPause
function to pause the lifecycle data collection:
To ensure accurate session and crash reporting, this call must be added to every Activity
.
Copied to your clipboard@Overridepublic void onPause() {MobileCore.lifecyclePause();}
Objective-C
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method. This will register the extension with Core and begin Lifecycle event processing:
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{...}];return YES;}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theAEPMobileCore::registerExtensions:
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, and begin event processing with Coreconst UIApplicationState appState = application.applicationState;[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{// only start lifecycle if the application is not in the backgroundif (appState != UIApplicationStateBackground) {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore lifecyclePause];}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
Swift
- Register the Lifecycle extension with the SDK Core by adding the following to your app's
application:didFinishLaunchingWithOptions:
delegate method. This will register the extension with Core and begin Lifecycle event processing:
Copied to your clipboardfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {MobileCore.registerExtensions([Lifecycle.self, ...], {...}}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theMobileCore.registerExtensions
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 {let appState = application.applicationStateMobileCore.registerExtensions([Lifecycle.self, ...], {if appState != .background {// only start lifecycle if the application is not in the backgroundMobileCore.lifecycleStart(additionalContextData: 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) {MobileCore.lifecycleStart(additionalContextData: 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) {MobileCore.lifecycleStart(additionalContextData: 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) {MobileCore.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) {MobileCore.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. This will register the extension with Core and begin Lifecycle event processing:
Copied to your clipboard- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// register the lifecycle extension[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{...}];return YES;}
- Start Lifecycle data collection by calling
lifecycleStart:
from within the callback of theAEPMobileCore::registerExtensions:
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, and begin event processing with Coreconst UIApplicationState appState = application.applicationState;[AEPMobileCore registerExtensions:@[AEPMobileLifecycle.class, ...] completion:^{// only start lifecycle if the application is not in the backgroundif (appState != UIApplicationStateBackground) {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore 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 {[AEPMobileCore lifecyclePause];}
For more information on handling backgrounding applications with Scenes, refer to Apple's documentation here
For more information, see the documentation on Lifecycle metrics.