Mobile Core API reference

Application reference (Android Only)

When building Android applications, the android.app.Application reference must be passed to the Mobile SDK, which allows the Mobile SDK to access the android.app.Context and monitor the lifecycle of the Android application.

Android applications must call MobileCore.setApplication() before calling any other Mobile SDK API.

Set Application

You can use this API to pass the Android Application instance to the SDK.

Android

Java

setApplication

Syntax

public static void setApplication(final Application app)

Example

public class CoreApp extends Application {
@Override
public void onCreate() {
super.onCreate();
MobileCore.setApplication(this);
MobileCore.start(null);
}
}

Get Application

You can use this API to get the previously set Android Application instance, and this instance is mainly provided for the third-party extensions.

Android

Java

getApplication

MobileCore.getApplication might return null if the Application object was destroyed or if MobileCore.setApplication was not previously called.

Syntax

public static Application getApplication()

Example

Application app = MobileCore.getApplication();
if (app != null) {
...
}

Track app actions

Actions are events that occur in your app. You can use this API to track and measure an action. Each action has one or more corresponding metrics that are incremented each time the event occurs. For example, you might call this API for each new subscription each time an article is viewed, or each time a level is completed.

Call this API when an event that you want to track occurs. In addition to the action name, you can send additional context data with each track action call.

If you have the Analytics extension set up, this method sends an Analytics action tracking hit with the optional context data that you provide.

Android
iOS
React Native

Java

trackAction

Syntax

public static void trackAction(final String action, final Map<String, String> contextData)

Example

Map<String, String> additionalContextData = new HashMap<String, String>();
additionalContextData.put("customKey", "value");
MobileCore.trackAction("loginClicked", additionalContextData);

Objective-C

trackAction

Syntax

+ (void) trackAction: (nullable NSString*) action data: (nullable NSDictionary*) data;

Example

[ACPCore trackAction:@"action name" data:@{@"key":@"value"}];

Swift

trackAction

Syntax

+ (void) trackAction: (nullable NSString*) action data: (nullable NSDictionary*) data;

Example

ACPCore.trackAction("action name", data: ["key": "value"])

JavaScript

trackAction

ACPCore.trackAction("action-name", {"key": "value"});

Track app states and views

States represent screens or views in your app. Each time a new state is displayed in your application, for example, when a user navigates from the home page to the news feed, this API can be called. This method sends an Analytics state tracking hit with optional context data.

If you have the Analytics extension set up, this API increments page views and an Analytics state tracking hit with the optional context data that you provide.

Android
iOS
React Native

Java

In Android, trackState is typically called each time a new Activity is loaded.

trackState

Syntax

public static void trackState(final String state, final Map<String, String> contextData)

Example

Map<String, String> additionalContextData = new HashMap<String, String>(); additionalContextData.put("customKey", "value"); MobileCore.trackState("homePage", additionalContextData);

Objective-C

trackState

Syntax

+ (void) trackState: (nullable NSString*) state data: (nullable NSDictionary*) data;

Example

[ACPCore trackState:@"state name" data:@{@"key":@"value"}];

Swift

trackState

Syntax

+ (void) trackState: (nullable NSString*) state data: (nullable NSDictionary*) data;

Example

ACPCore.trackState("state name", data: ["key": "value"])

JavaScript

trackState

ACPCore.trackState("state-name", {"key": "value"});

Collect PII

This API allows the SDK to collect sensitive or personally identifiable information (PII) data.

While this API enables the collection of sensitive data, no data is actually sent to any Adobe or third-party endpoints. To send the data to an endpoint, use a postback of the PII type.

Android
iOS
React Native

Java

collectPii

Syntax

public static void collectPII(final Map<String, String> piiData);

Example

Map<String, String> data = new HashMap<String, String>();
data.put("firstname", "customer");
//The rule to trigger a PII needs to be setup for this call
//to result in a network send
MobileCore.collectPII(data);

Objective-C

collectPii

Syntax

+ (void) collectPii: (nonnull NSDictionary<NSString*, NSString*>*) data;

Example

[ACPCore collectPii:data:@{@"key1" : "@value1",
@"key2" : "@value2"
}];

Swift

collectPii

Syntax

ACPCore.collectPii(data: [String : String])

JavaScript

ACPCore.collectPii({"myPii": "data"});

Collect launch information

You can provide the user information to the SDK from various launch points in your application.

If the Analytics extension is enabled in your SDK, collecting this launch data results in an Analytics request being sent. Other extensions in the SDK might use the collected data, for example, as a rule condition for an In-App Message.

Android
iOS

Coming soon

Objective-C

This method should be called to support the following use cases:

  • Tracking Deep Link click-throughs

    • From application:didFinishLaunchingWithOptions

    • Extract userInfo from UIApplicationLaunchOptionsURLKey

  • Tracking Push Message click-through

    • From application:didReceiveRemoteNotification:fetchCompletionHandler:

collectLaunchInfo

Syntax

+ (void) collectLaunchInfo: (nonnull NSDictionary*) userInfo;

Example

[ACPCore collectLaunchInfo:launchOptions];

Swift

This method should be called to support the following use cases:

  • Tracking Deep Link click-throughs

    • From application(_:didFinishLaunchingWithOptions:)

    • Extract userInfo from url: UIApplication.LaunchOptionsKey

  • Tracking Push Message click-through

    • From application(_:didReceiveRemoteNotification:fetchCompletionHandler:)

collectLaunchInfo

Syntax

+ (void) collectLaunchInfo: (nonnull NSDictionary*) userInfo;

Example

ACPCore.collectLaunchInfo(userInfo)

Set Icons for local notification (Android Only)

Set the small and large icons that will be used for notifications that are created by the SDK. The small icon appears in the status bar and is the secondary image that is displayed when the user sees the complete notification in the notification center. The large icon is the primary image that is displayed when the user sees the complete notification in the notification center.

Those APIs are Android only.

Android

Java

setSmallIconResourceID

Syntax

public static void setSmallIconResourceID(int resourceID)

Example

MobileCore.setSmallIconResourceID(R.mipmap.ic_launcher_round);

setLargeIconResourceID

Syntax

public static void setLargeIconResourceID(int resourceID)

Example

MobileCore.setLargeIconResourceID(R.mipmap.ic_launcher_round);

Logging

The logging APIs allow log messages to be tagged and filtered with the Mobile SDK log messages and allow application developers to filter the logged messages based on the current logging mode.

Application developers can use the setLogLevel API to filter the log messages that are coming from the Mobile SDK. When debugging, use LoggingMode.VERBOSE (Android) / ACPMobileLogLevelVerbose (iOS) to enable all the logging messages coming from the Mobile SDK and partner extensions. In a production application, we recommend that you use a less verbose logging mode, for example LoggingMode.ERROR (Android) / ACPMobileLogLevelError (iOS).

By default, the Mobile SDK logging mode is set to LoggingMode.ERROR (Android) / ACPMobileLogLevelError (iOS).

As a Mobile SDK extension developer, use the MobileCore (Android) / ACPCore (iOS) log API to include extension log messages with Mobile SDK core log messages.

From least to most verbose, the order of the mobile SDK logging modes is as follows:

  • ERROR

  • WARNING

  • DEBUG

  • VERBOSE

In Android, Mobile SDK uses android.util.Log class for printing the messages.

In iOS, Mobile SDK uses NSLog for logging the message to Apple System Log facility.

Android
iOS
React Native

Java

setLogLevel

Syntax

public static void setLogLevel(LoggingMode mode)

Example

import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
...
MobileCore.setLogLevel(LoggingMode.VERBOSE);

Objective-C

setLogLevel

Syntax

+ (void) setLogLevel: (ACPMobileLogLevel) logLevel;

Example

#import "ACPCore.h"
...
[ACPCore setLogLevel: ACPMobileLogLevelVerbose];

Swift

setLogLevel

Syntax

+ (void) setLogLevel: (ACPMobileLogLevel) logLevel;

Example

import ACPCore
...
ACPCore.setLogLevel(ACPMobileLogLevel.verbose);

JavaScript

setLogLevel

import {ACPMobileLogLevel} from '@adobe/react-native-acpcore';
ACPCore.setLogLevel(ACPMobileLogLevel.VERBOSE);
Android
iOS
React Native

Java

getLogLevel

Syntax

public static LoggingMode getLogLevel()

Example

LoggingMode mode = MobileCore.getLogLevel();

Objective-C

getLogLevel

Syntax

+ (ACPMobileLogLevel) logLevel;

Example

var logLevel:ACPMobileLogLevel = [ACPCore logLevel];

Swift

getLogLevel

Syntax

+ (ACPMobileLogLevel) logLevel;

Example

let logLevel:ACPMobileLogLevel = ACPCore.logLevel();

JavaScript

getLogLevel

ACPCore.getLogLevel().then(level => console.log("AdobeExperienceSDK: Log Level = " + level));
Android
iOS
React Native

Java

The MobileCore logging APIs use the android.util.Log APIs to log messages to Android. Based on the LoggingMode passed to MobileCore.log(), the following Android method is called:

  • LoggingMode.VERBOSE uses android.util.Log.v

  • LoggingMode.DEBUG uses android.util.Log.d

  • LoggingMode.WARNING uses android.util.Log.w

  • LoggingMode.ERROR uses android.util.Log.e

All log messages from the Adobe Experience SDK to Android use the same log tag of AdobeExperienceSDK. For example, if logging an error message is using MobileCore.log(), the call to android.util.Log.e looks like Log.e("AdobeExperienceSDK", tag + " - " + message).

log

Syntax

public static void log(final LoggingMode mode, final String tag, final String message)

Example

MobileCore.log(LoggingMode.DEBUG, "MyClassName", "Provided data was null");

Output Example

D/AdobeExperienceSDK: MyClassName - Provided data was null

Objective-C

The log messages from the Adobe Experience SDK are printed to the Apple System Log facility and use a common format that contains the tag AdobeExperienceSDK. For example, if logging an error message using ACPCore.log(), the printed output looks like [AdobeExperienceSDK ERROR <tag>]: message.

log

Syntax

+ (void) log: (ACPMobileLogLevel) logLevel tag: (nonnull NSString*) tag message: (nonnull NSString*) message;

Example

[ACPCore log: ACPMobileLogLevelDebug, tag:@"MyClassName", message:@"Provided data was nil"];

Output Example

[AdobeExperienceSDK DEBUG <MyClassName>]: Provided data was nil

Swift

log

Syntax

+ (void) log: (ACPMobileLogLevel) logLevel tag: (nonnull NSString*) tag message: (nonnull NSString*) message;

Example

ACPCore.log(ACPMobileLogLevel.debug, tag: "MyClassName", message: "Provided data was nil");

Output Example

[AdobeExperienceSDK DEBUG <MyClassName>]: Provided data was nil

JavaScript

The log messages from the Adobe Experience SDK are printed to the Log facility and use a common format that contains the tag ACPMobileLogLevel. For example, if logging an error message using ACPCore.log(), the printed output looks like

ACPCore.log(ACPMobileLogLevel.ERROR, "React Native Tag", "React Native Message");

Note: ACPMobileLogLevel contains the following getters:

const ERROR = "ACP_LOG_LEVEL_ERROR";
const WARNING = "ACP_LOG_LEVEL_WARNING";
const DEBUG = "ACP_LOG_LEVEL_DEBUG";
const VERBOSE = "ACP_LOG_LEVEL_VERBOSE";

Handle open URL action

The Mobile SDK allows users to add a callback function that is triggered before the open url action occurrs. If the callback function returns YES, the SDK does not complete the open url action. If the callback function returns NO, the SDK completes the open url action.

iOS

Objective-C

registerURLHandler

Syntax

+ (void) registerURLHandler: (nonnull BOOL (^) (NSString* __nullable url)) callback;

Example

[ACPCore registerURLHandler:^BOOL(NSString * _Nullable url) {
...
}];

Additional Information