Skip to content

Latest commit

 

History

History
333 lines (242 loc) · 6.25 KB

File metadata and controls

333 lines (242 loc) · 6.25 KB

Lifecycle API reference

Version of the Lifecycle extension

The extensionVersion() API returns the version of the Lifecycle extension that is registered with the Mobile Core extension.

To get the version of the Lifecycle extension, use the following code sample:

{% tabs %} {% tab title="Android" %}

Java

String lifecycleExtensionVersion = Lifecycle.extensionVersion();

{% endtab %}

{% tab title="iOS" %} Objective C

NSString *lifecycleExtensionVersion = [ACPLifecycle extensionVersion];

Swift

let lifecycleExtensionVersion  = ACPLifecycle.extensionVersion()

{% endtab %}

{% tab title="React Native" %}

JavaScript

ACPLifecycle.extensionVersion().then(lifecycleExtensionVersion => console.log("AdobeExperienceSDK: ACPLifecycle version: " + lifecycleExtensionVersion));

{% endtab %}

{% tab title="Flutter" %}

Dart

String lifeycycleExtensionVersion = await FlutterACPLifecycle.extensionVersion;

{% endtab %}

{% tab title="Cordova" %}

Cordova

ACPLifecycle.extensionVersion(function(version) {  
   console.log("ACPLifecycle version: " + version);
}, function(error) {  
   console.log(error);  
});

{% endtab %}

{% tab title="Unity" %}

C#

string lifecycleVersion = ACPLifecycle.ExtensionVersion();

{% endtab %}

{% tab title="Xamarin" %}

C#

string lifecycleVersion = ACPLifecycle.ExtensionVersion();

{% endtab %} {% endtabs %}

Lifecycle Start

You can use this API to start a new lifecycle session or resume a previously paused lifecycle session. If a previously paused session timed out, then a new session is created. If a current session is running, then calling this method does nothing.

lifecycleStart

{% tabs %} {% tab title="Android" %}

Java

Syntax

public static void lifecycleStart(final Map<String, String> additionalContextData);

Example

MobileCore.lifecycleStart(null);

If you need to collect additional lifecycle data:

contextData.put("myapp.category", "Game");
MobileCore.lifecycleStart(additionalContextData);

{% hint style="warning" %} This method should be called from the Activity onResume method. {% endhint %} {% endtab %}

{% tab title="iOS" %}

Objective-C

Syntax

+ (void) lifecycleStart: (nullable NSDictionary<NSString*, NSString*>*) additionalContextData;

Example

[ACPCore lifecycleStart:nil];

If you need to collect additional lifecycle data:

[ACPCore lifecycleStart:@{@"state": @"appResume"}];

Swift

ACPCore.lifecycleStart(["state": "appResume"])

{% endtab %}

{% tab title="React Native" %}

JavaScript

Note: Implementing Lifecycle via JavaScript may lead to inaccurate Lifecycle metrics, therefore we recommend implementing Lifecycle in native Android and iOS code. However, these APIs are still provided in JavaScript to support flexible Lifecycle implementations.

Syntax

lifecycleStart(additionalContextData?: { string: string });

Example

ACPCore.lifecycleStart({"lifecycleStart": "myData"});

{% endtab %}

{% tab title="Cordova" %}

Cordova

When using Cordova, the lifecycleStart method call must be done in native code which is shown under the Android and iOS tabs. {% endtab %}

{% tab title="Unity" %}

C#

When using Unity, the LifecycleStart method call must be done from the OnApplicationPausemethod.

private void OnApplicationPause(bool pauseStatus)
{
  if (!pauseStatus)
  {
    ACPCore.LifecyclePause();
  }
  else
  {
    var cdata = new Dictionary<string, string>();
    cdata.Add("launch.data", "added");
    ACPCore.LifecycleStart(cdata);
  }
}

{% endtab %}

{% tab title="Xamarin" %}

C#

iOS

When using iOS, the LifecycleStart method call must be done from the OnActivated method.

public override void OnActivated(UIApplication uiApplication)
{
  base.OnActivated(uiApplication);
  ACPCore.LifecycleStart(null);
}

Android

When using Android, the LifecycleStart method call must be done from the OnResume method.

protected override void OnResume()
{
  base.OnResume();
  ACPCore.LifecycleStart(null);
}

{% endtab %} {% endtabs %}

Lifecycle Pause

Use this API to pause or stop the collection of lifecycle data.

lifecyclePause

{% tabs %} {% tab title="Android" %}

Java

Syntax

public static void lifecyclePause()

Example

MobileCore.lifecyclePause();

{% endtab %}

{% tab title="iOS" %}

Objective-C

Syntax

+ (void) lifecyclePause;

Example

[ACPCore lifecyclePause];

Swift

ACPCore.lifecyclePause()

{% endtab %}

{% tab title="React Native" %}

JavaScript

Note: Implementing Lifecycle via JavaScript may lead to inaccurate Lifecycle metrics, therefore we recommend implementing Lifecycle in native Android and iOS code. However, these APIs are still provided in JavaScript to support flexible Lifecycle implementations.

Syntax

lifecyclePause();

Example

ACPCore.lifecyclePause();

{% endtab %}

{% tab title="Cordova" %}

Cordova

When using Cordova, the lifecyclePause method call must be done in native code which is shown under the Android and iOS tabs. {% endtab %}

{% tab title="Unity" %}

C#

When using Unity, the LifecyclePause method call must be done from the OnApplicationPausemethod.

private void OnApplicationPause(bool pauseStatus)
{
  if (!pauseStatus)
  {
    ACPCore.LifecyclePause();
  }
  else
  {
    var cdata = new Dictionary<string, string>();
    cdata.Add("launch.data", "added");
    ACPCore.LifecycleStart(cdata);
  }
}

{% endtab %}

{% tab title="Xamarin" %}

C#

iOS

When using iOS, the LifecyclePause method call must be done from the OnResignActivation method.

public override void OnResignActivation(UIApplication uiApplication)
{
  base.OnResignActivation(uiApplication);
  ACPCore.LifecyclePause();
}

Android

When using Android, the LifecyclePause method call must be done from the OnPause method.

protected override void OnPause()
{
  base.OnPause();
  ACPCore.LifecyclePause();
}

{% endtab %} {% endtabs %}