Mobile Core API reference
clearUpdatedConfiguration
Programmatic updates made to the configuration can be cleared via the clearUpdatedConfiguration API. For more information about configuration in Mobile Core, please refer to the Configuration API reference.
collectMessageInfo
User interactions with local or push notifications can be tracked by invoking the collectMessageInfo API. Please refer to this page for more information about tracking local and push notification message interactions.
collectLaunchInfo
You can provide the user information to the SDK from various launch points in your application.
data-variant=info
data-slots=text
Android
The Android SDK automatically registers an Application.ActivityLifecycleCallbacksand listens for onActivityResumed. When an activity is resumed, SDK collects the data from the activity. Currently, it is being used in the following scenarios:
- Tracking deep link clickthrough
- Tracking push message clickthrough
- Tracking Local Notification clickthrough
iOS Swift
This method should be called to support the following use cases:
-
Tracking deep link clickthroughs
- From
application(_:didFinishLaunchingWithOptions:) - Extract
userInfofromurl: UIApplication.LaunchOptionsKey
- From
-
Tracking push message clickthrough
- From
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
- From
data-slots=heading, code
data-repeat=2
Syntax
public static func collectLaunchInfo(_ userInfo: [String: Any])
Example
MobileCore.collectLaunchInfo(userInfo)
iOS Objective-C
This method should be called to support the following use cases:
-
Tracking deep link clickthroughs
- From
application:didFinishLaunchingWithOptions - Extract
userInfofromUIApplicationLaunchOptionsURLKey- Tracking push message clickthrough
- From
application:didReceiveRemoteNotification:fetchCompletionHandler:
- From
data-slots=heading, code
data-repeat=2
Syntax
@objc(collectLaunchInfo:)
public static func collectLaunchInfo(_ userInfo: [String: Any])
Example
[AEPMobileCore collectLaunchInfo:launchOptions];
collectPii
The collectPii method lets the SDK to collect sensitive or personally identifiable information (PII).
data-variant=warning
data-slots=text
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void collectPii(@NonNull final Map<String, String> data)
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);
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
public static func collectPii(_ data: [String: Any])
Example
MobileCore.collectPii(["key1" : "value1","key2" : "value2"]);
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(collectPii:)
public static func collectPii(_ data: [String: Any])
Example
[AEPMobileCore collectPii:data:@{@"key1" : @"value1",
@"key2" : @"value2"
}];
configureWithAppId
The configureWithAppId API can be used to download the configuration for the provided app ID and apply the configuration to the current session. For more information about configuration in Mobile Core, please refer to the Configuration API reference.
configureWithFileInAssets
You can bundle a JSON configuration file in the app's assets folder and use configureWithFileInAssets API to replace or complement the configuration that was downloaded using the configureWithAppId API. For more information about configuration in Mobile Core, please refer to the Configuration API reference.
configureWithFileInPath
You can bundle a JSON configuration file in you app package and use configureWithFileInPath API to replace or complement the configuration that was downloaded using the configureWithAppId API. For more information about configuration in Mobile Core, please refer to the Configuration API reference.
dispatch / dispatchEvent
This method can be used to send an event through the Mobile Core for other extensions to consume.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void dispatchEvent(@NonNull final Event event)
Example
final Map<String, Object> eventData = new HashMap<>();
eventData.put("sampleKey", "sampleValue");
final Event sampleEvent = new Event.Builder("SampleEventName", "SampleEventType", "SampleEventSource")
.setEventData(eventData)
.build();
MobileCore.dispatchEvent(sampleEvent);
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
public static func dispatch(event: Event)
Example
let event = Event(name: "Sample Event Name", type: EventType.custom, source: EventType.custom, data: ["sampleKey": "sampleValue"])
MobileCore.dispatch(event: event)
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(dispatch:)
public static func dispatch(event: Event)
Example
AEPEvent *event = [[AEPEvent alloc] initWithName:@"Sample Event Name" type:AEPEventType.custom source:AEPEventType.custom data:@{@"sampleKey": @"sampleValue"}];
[AEPMobileCore dispatch:event];
dispatch / dispatchEventWithResponseCallback
This method can be used to send an event through the Mobile Core for other extensions to consume. The provided event is used as a trigger and in return a response event is provided as a callback. The callback is invoked with a null event if the response could not be provided within the given timeout.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void dispatchEventWithResponseCallback(@NonNull final Event event, final long timeoutMS, @NonNull final AdobeCallbackWithError<Event> responseCallback)
Example
final Map<String, Object> eventData = new HashMap<>();
eventData.put("sampleKey", "sampleValue");
final Event sampleEvent = new Event.Builder("My Event", "SampleEventType", "SampleEventSource")
.setEventData(eventData)
.build();
MobileCore.dispatchEventWithResponseCallback(sampleEvent, 5000L, new AdobeCallbackWithError<Event>() {
// handle response event
});
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
public static func dispatch(event: Event, timeout: TimeInterval = 1, responseCallback: @escaping (Event?) -> Void)
Example
let event = Event(name: "My Event", type: EventType.custom, source: EventType.custom, data: ["sampleKey": "sampleValue"])
MobileCore.dispatch(event: event) { (responseEvent) in
// handle responseEvent
}
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(dispatch:timeout:responseCallback:)
public static func dispatch(event: Event, timeout: TimeInterval = 1, responseCallback: @escaping (Event?) -> Void)
Example
AEPEvent *event = [[AEPEvent alloc] initWithName:@"My Event" type:AEPEventType.custom source:AEPEventType.custom data:@{@"sampleKey": @"sampleValue"}];
[AEPMobileCore dispatch:event responseCallback:^(AEPEvent * _Nullable responseEvent) {
// handle responseEvent
}];
getApplication
You can use the getApplication method to get the previously set Android Application instance. The Application instance is mainly provided for third-party extensions.
Android Java
MobileCore.getApplication will return null if the Application object was destroyed or if MobileCore.setApplication was not previously called.
data-slots=heading, code
data-repeat=2
Syntax
@Nullable
public static Application getApplication()
Example
Application app = MobileCore.getApplication();
if (app != null) {
...
}
getLogLevel
This API gets the current log level being used in the SDK.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
@NonNull
public static LoggingMode getLogLevel()
Example
LoggingMode mode = MobileCore.getLogLevel();
The logLevel getter has been deprecated. To get the log level in the Swift AEP 3.x SDKs, please use Log.logFilter instead.
iOS Swift
This variable is part of the Log class within AEPServices.
data-slots=heading, code
data-repeat=2
Syntax
public static var logFilter: LogLevel
Example
var logLevel = Log.logFilter
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc public static var logFilter: LogLevel
Example
AEPLogLevel logLevel = [AEPLog logFilter];
getPrivacyStatus
You can use the getPrivacyStatus API to retrieve the current privacy status. For more information about privacy in Mobile Core, please see Privacy and GDPR
getSdkIdentities
The following SDK identities are locally stored:
- Company Context - IMS Org IDs
- Experience Cloud ID (MID)
- User IDs
- Integration codes (ADID, push IDs)
- Data source IDs (DPID, DPUUID)
- Analytics IDs (AVID, AID, VID, and associated RSIDs)
- Target legacy IDs (TNTID, TNT3rdpartyID)
- Audience Manager ID (UUID)
To retrieve data as a JSON string from the SDKs and send this data to your servers, use the getSdkIdentities method.
data-variant=warning
data-slots=text1, text2
Android Java
- callback is invoked with the SDK identities as a JSON string. If an instance of
AdobeCallbackWithErroris provided, and you are fetching the attributes from the Mobile SDK, the timeout value is 5000ms. If the operation times out or an unexpected error occurs, thefailmethod is called with the appropriateAdobeError.
data-slots=heading, code
data-repeat=2
Syntax
void getSdkIdentities(@NonNull AdobeCallback<String> callback);
Example
MobileCore.getSdkIdentities(new AdobeCallback<String>() {
@Override
public void call(String value) {
// handle the json string
}
});
iOS Swift
- callback is invoked with the SDK identities as a JSON string.
- completionHandler is invoked with the SDK identities as a JSON string, or error if an unexpected error occurs or the request times out. The default timeout is 1000ms.
data-slots=heading, code
data-repeat=2
Syntax
static func getSdkIdentities(completion: @escaping (String?, Error?) -> Void)
Example
MobileCore.getSdkIdentities { (content, error) in
// handle completion
}
iOS Objective-C
- callback is invoked with the SDK identities as a JSON string.
- completionHandler is invoked with the SDK identities as a JSON string, or error if an unexpected error occurs or the request times out. The default timeout is 1000ms.
data-slots=heading, code
data-repeat=2
Syntax
@objc(getSdkIdentities:)
static func getSdkIdentities(completion: @escaping (String?, Error?) -> Void)
Example
[AEPMobileCore getSdkIdentities:^(NSString * _Nullable content, NSError * _Nullable error) {
if (error) {
// handle error here
} else {
// handle the retrieved identities
}
}];
initialize
data-variant=info
data-slots=text
data-variant=info
data-slots=text
This API initializes AEP SDKs by automatically registering all extensions bundled with the application and enabling automatic lifecycle tracking by default. The completion callback is triggered once the SDK is fully initialized, allowing event processing to begin.
Two versions of this API are available, which accept app ID or InitOptions:
- app ID: Configures the SDK with the provided mobile property environment ID configured from the Data Collection UI.
Android Java
- application The Android Application instance.
- appID The mobile property environment ID configured from the Data Collection UI.
- completionCallback An Optional AdobeCallback triggered once initialization is complete.
data-slots=heading, code
data-repeat=2
Syntax
public static void initialize(
@NonNull final Application application,
@NonNull final String appId,
@Nullable final AdobeCallback<?> completionCallback)
Example
public class CoreApp extends Application {
@Override
public void onCreate() {
super.onCreate();
MobileCore.initialize(this, "ENVIRONMENT_ID", o -> {
Log.d(LOG_TAG, "AEP Mobile SDK is initialized");
});
}
}
iOS Swift
- appId The mobile property environment ID configured from the Data Collection UI.
- completion An Optional callback triggered once initialization is complete.
data-slots=heading, code
data-repeat=2
Syntax
public static func initialize(appId: String, _ completion: (() -> Void)? = nil)
Example
// AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
MobileCore.initialize(appId: "ENVIRONMENT_ID") {
print("AEP Mobile SDK is initialized")
}
...
}
iOS Objective-C
- appId The mobile property environment ID configured from the Data Collection UI.
- completion An Optional callback triggered once initialization is complete.
data-slots=heading, code
data-repeat=2
Syntax
@objc(initializeWithAppId:completion:)
public static func initialize(appId: String, _ completion: (() -> Void)? = nil)
Example
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[AEPMobileCore initializeWithAppId:@"ENVIRONMENT_ID" completion:^{
NSLog(@"AEP Mobile SDK is initialized");
}];
...
}
- InitOptions: Allow customization of the default initialization behavior. Refer InitOptions.
Android Java
- application The Android Application instance.
- initOptions The InitOptions to configure the SDK.
- completionCallback An Optional AdobeCallback triggered once initialization is complete.
data-slots=heading, code
data-repeat=2
Syntax
public static void initialize(
@NonNull final Application application,
@NonNull final InitOptions initOptions,
@Nullable final AdobeCallback<?> completionCallback)
Example
public class CoreApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// Use InitOptions to disable automatic lifecycle tracking.
InitOptions initOptions = InitOptions.configureWithAppID("ENVIRONMENT_ID")
initOptions.lifecycleAutomaticTrackingEnabled = false
MobileCore.initialize(this, initOptions, o -> {
Log.d(LOG_TAG, "AEP Mobile SDK is initialized");
});
}
}
iOS Swift
- options The InitOptions to configure the SDK.
- completion An Optional callback triggered once initialization is complete.
data-slots=heading, code
data-repeat=2
Syntax
public static func initialize(options: InitOptions, _ completion: (() -> Void)? = nil)
Example
// AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Use InitOptions to disable automatic lifecycle tracking.
let options = InitOptions(appId: "ENVIRONMENT_ID")
options.lifecycleAutomaticTrackingEnabled = false
MobileCore.initialize(options: options) {
print("AEP Mobile SDK is initialized")
}
...
}
iOS Objective-C
- options The InitOptions to configure the SDK.
- completion An Optional callback triggered once initialization is complete.
data-slots=heading, code
data-repeat=2
Syntax
@objc(initializeWithOptions:completion:)
public static func initialize(options: InitOptions, _ completion: (() -> Void)? = nil)
Example
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Use InitOptions to disable automatic lifecycle tracking.
AEPInitOptions *options = [[AEPInitOptions alloc] initWithAppId:@"ENVIRONMENT_ID"];
options.lifecycleAutomaticTrackingEnabled = NO;
[AEPMobileCore initializeWithOptions:options completion:^{
NSLog(@"AEP Mobile SDK is initialized");
}];
...
}
log
This is the API used to log from the SDK.
This API was deprecated in v2.0.0 of the Mobile Core extension. Use the com.adobe.marketing.mobile.services.Log instead.
Android Java
The MobileCore logging APIs use the android.util.Log APIs to log messages to Android. Based on the LoggingMode that is passed to MobileCore.log(), the following Android method is called:
LoggingMode.VERBOSEusesandroid.util.Log.vLoggingMode.DEBUGusesandroid.util.Log.dLoggingMode.WARNINGusesandroid.util.Log.wLoggingMode.ERRORusesandroid.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).
data-slots=heading, code
data-repeat=2
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
D/AdobeExperienceSDK: MyClassName - Provided data was null
iOS Swift
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 AEP SDK. For example, if logging an error message using Log.error(label:_ message:_), the printed output looks like [AEP SDK ERROR <label>]: message.
data-slots=heading, code
data-repeat=2
Syntax
public static func trace(label: String, _ message: String) {
public static func debug(label: String, _ message: String)
public static func warning(label: String, _ message: String) {
public static func error(label: String, _ message: String) {
Example
Log.trace(label: "testLabel", "Test message")
Log.debug(label: "testLabel", "Test message")
Log.warning(label: "testLabel", "Test message")
Log.error(label: "testLabel", "Test message")
iOS 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 AEP SDK. For example, if logging an error message using [AEPLog errorWithLabel: _ message:_], the printed output looks like [AEP SDK ERROR <label>]: message.
data-slots=heading, code
data-repeat=2
Syntax
@objc(traceWithLabel:message:)
public static func trace(label: String, _ message: String)
@objc(debugWithLabel:message:)
public static func debug(label: String, _ message: String)
@objc(warningWithLabel:message:)
public static func warning(label: String, _ message: String)
@objc(errorWithLabel:message:)
public static func error(label: String, _ message: String)
Example
[AEPLog traceWithLabel:@"testLabel" message:@"testMessage"];
[AEPLog debugWithLabel:@"testLabel" message:@"testMessage"];
[AEPLog warningWithLabel:@"testLabel" message:@"testMessage"];
[AEPLog errorWithLabel:@"testLabel" message:@"testMessage"];
registerEventListener
An EventListener can be registered with MobileCore to be notified when Events matching a type and source are dispatched.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void registerEventListener(@NonNull final String eventType, @NonNull final String eventSource, @NonNull final AdobeCallback<Event> callback)
Example
MobileCore.registerEventListener(EventType.CONFIGURATION, EventSource.RESPONSE_CONTENT, new AdobeCallback<Event>() {
@Override
public void call(Event value) {
// handle event
}
});
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
public static func registerEventListener(type: String, source: String, listener: @escaping EventListener)
Example
MobileCore.registerEventListener(type: EventType.configuration, source: EventSource.responseContent, listener: { event in
// handle event
})
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(registerEventListenerWithType:source:listener:)
public static func registerEventListener(type: String, source: String, listener: @escaping EventListener)
Example
[AEPMobileCore registerEventListenerWithType: type source: source listener:^(AEPEvent * _Nonnull event) {
// handle event
}];
registerExtension
Extensions can be incrementally registered with Mobile Core using the registerExtension API.
Android Java
data-variant=warning
data-slots=text1, text2
MobileCore.start() API is no longer required when using MobileCore.registerExtensions().data-slots=heading, code
data-repeat=2
Syntax
public static boolean registerExtension(@NonNull final Class<? extends Extension> extensionClass, @Nullable final ExtensionErrorCallback<ExtensionError> errorCallback)
Example
MobileCore.registerExtension(Signal.EXTENSION, errorCallback -> {
// handle callback
});
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
public static func registerExtension(_ exten: Extension.Type, _ completion: (() -> Void)? = nil)
Example
MobileCore.registerExtension(Lifecycle.self) {
// handle completion
}
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(registerExtension:completion:)
public static func registerExtension(_ exten: Extension.Type, _ completion: (() -> Void)? = nil)
Example
[AEPMobileCore registerExtension:AEPMobileLifecycle.class completion:^{
// handle completion
}];
registerExtensions
Extensions are registered with Mobile Core so that they can dispatch and listen for events. This API can be used to register desired extensions and boot up the SDK for event processing. Calling MobileCore.start() API is deprecated starting Mobile Core v2.0.0 and is no longer required when using MobileCore.registerExtensions().
data-variant=warning
data-slots=text
The following code snippets demonstrate how Lifecycle, Signal, Profile, Edge, and other extensions are imported and registered.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void registerExtensions(@NonNull final List<Class<? extends Extension>> extensions, @Nullable final AdobeCallback<?> completionCallback)
Example
import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.edge.consent.Consent;
import com.adobe.marketing.mobile.edge.identity.Identity;
import com.adobe.marketing.mobile.Lifecycle;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Signal;
import com.adobe.marketing.mobile.UserProfile;
...
import android.app.Application;
...
public class MainApp extends Application {
// Set up the preferred Environment File ID from your mobile property configured in Data Collection UI
private static final String ENVIRONMENT_FILE_ID = "YOUR_ENVIRONMENT_FILE_ID";
@Override
public void onCreate() {
super.onCreate();
MobileCore.setApplication(this);
MobileCore.configureWithAppID(ENVIRONMENT_FILE_ID);
List<Class<? extends Extension>> extensions = Arrays.asList(
Lifecycle.EXTENSION,
Signal.EXTENSION,
UserProfile.EXTENSION
Edge.EXTENSION,
Consent.EXTENSION,
EdgeIdentity.EXTENSION);
MobileCore.registerExtensions(extensions, o -> {
Log.d(LOG_TAG, "AEP Mobile SDK is initialized");
});
}
}
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
public static func registerExtensions(_ extensions: [NSObject.Type], _ completion: (() -> Void)? = nil)
Example
// AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
MobileCore.registerExtensions([Signal.self, Lifecycle.self, UserProfile.self, Edge.self, AEPEdgeIdentity.Identity.self, Consent.self], {
MobileCore.configureWith(appId: "yourAppId")
})
...
}
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(registerExtensions:completion:)
public static func registerExtensions(_ extensions: [NSObject.Type], _ completion: (() -> Void)? = nil)
Example
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[AEPMobileCore registerExtensions:@[AEPMobileSignal.class, AEPMobileLifecycle.class, AEPMobileUserProfile.class, AEPMobileEdge.class, AEPMobileEdgeIdentity.class, AEPMobileEdgeConsent.class] completion:^{
[AEPMobileCore configureWithAppId: @"yourAppId"];
}];
...
}
resetIdentities
The resetIdentities method requests that each extension resets the identities it owns and each extension responds to this request uniquely. For more details, check the resetIdentities API reference on each of the extensions you use.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
void resetIdentities();
Example
MobileCore.resetIdentities();
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
static func resetIdentities()
Example
MobileCore.resetIdentities()
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(resetIdentities)
static func resetIdentities()
Example
[AEPMobileCore resetIdentities];
setAdvertisingIdentifier
The advertising ID is preserved between app upgrades, is saved and restored during the standard application backup process, available via Signals, and is removed at uninstall.
For more information about identity in Mobile Core, please read the documentation on the identity APIs.
setAppGroup
You can use the setAppGroup method to set the app group, which is used to share user defaults and files among the containing app and the extension apps. Please note that this method is only supported on iOS versions of Mobile Core.
data-variant=info
data-slots=text
AppDidFinishLaunching and before any other interactions with the Adobe Experience SDK have happened. Only the first call to this function will have any effect.iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
public static func setAppGroup(_ group: String?)
Example
MobileCore.setAppGroup("appGroupId")
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(setAppGroup:)
public static func setAppGroup(_ group: String?)
Example
[AEPMobileCore setAppGroup:@"app-group-id"];
setApplication
When building Android applications, the android.app.Application reference must be passed to Mobile SDK, which allows Mobile SDK to access the android.app.Context and monitor the lifecycle of the Android application.
data-variant=warning
data-slots=text
MobileCore.setApplication() before calling any other Mobile SDK API. This can be skipped if you are using simplified initialization with the initialize API.You can use the setApplication method to pass the Android Application instance to Mobile SDK. Please note that this method is only supported on Android versions of Mobile Core.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void setApplication(@NonNull final Application app)
Example
public class CoreApp extends Application {
@Override
public void onCreate() {
super.onCreate();
MobileCore.setApplication(this);
List<Class<? extends Extension>> extensions = Arrays.asList(
Lifecycle.EXTENSION, Signal.EXTENSION, UserProfile.EXTENSION...);
MobileCore.registerExtensions(extensions, o -> {
Log.d(LOG_TAG, "AEP Mobile SDK is initialized");
});
}
}
setLogLevel
The logging APIs allow log messages to be tagged and filtered with the Mobile SDK log messages. This allows application developers to filter the logged messages based on the current logging mode.
Application developers can use the setLogLevel method to filter the log messages that are coming from the Mobile SDK.
From least to most verbose, the order of Mobile SDK logging modes is as follows:
- ERROR
- WARNING
- DEBUG
- VERBOSE / TRACE
When debugging on iOS, you can use LogLevel.verbose to enable all the logging messages that are coming from Mobile SDK and partner extensions. Similarly, on Android, you can use LoggingMode.VERBOSE to enable all the logging messages that are coming from Mobile SDK and partner extensions.
In a production application, you should use a less verbose logging mode, such as error-level logging.
By default, Mobile SDK logging mode is set to LoggingMode.ERROR for Android and LogLevel.erroron iOS.
data-variant=info
data-slots=text1, text2
android.util.Log class to log messages.NSLog to messages to Apple System Log facility.Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void setLogLevel(@NonNull LoggingMode mode)
Example
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
MobileCore.setLogLevel(LoggingMode.VERBOSE);
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
public static func setLogLevel(_ level: LogLevel)
Example
import AEPCore
import AEPServices
MobileCore.setLogLevel(.trace)
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(setLogLevel:)
public static func setLogLevel(_ level: LogLevel)
Example
@import AEPCore;
@import AEPServices;
[AEPMobileCore setLogLevel: AEPLogLevelTrace];
setPrivacyStatus
You can use the setPrivacyStatus API to set the privacy status. For more information about privacy in Mobile Core, please see Privacy and GDPR API's.
setPushIdentifier
This API sets the device token for push notifications in the SDK. If the current SDK privacy status is optedout, the push identifier is not set.
data-variant=info
data-slots=text
setPushIdentifier on each application launch to ensure the most up-to-date device token is set to the SDK. If no device token is available, null/nil should be passed.Android Java
- pushIdentifier is a string that contains the device token for push notifications.
data-slots=heading, code
data-repeat=2
Syntax
public static void setPushIdentifier(@Nullable final String pushIdentifier);
Example
//Retrieve the token from either GCM or FCM, and pass it to the SDK
MobileCore.setPushIdentifier(token);
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
public static func setPushIdentifier(_ deviceToken: Data?)
Example
MobileCore.setPushIdentifier(deviceToken)
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(setPushIdentifier:)
public static func setPushIdentifier(_ deviceToken: Data?)
Example
[AEPMobileCore setPushIdentifier:deviceToken];
setSmallIconResourceID / setLargeIconResourceID
You can 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. Please note that this method is only supported on Android versions of Mobile Core.
Android Java
setSmallIconResourceID
data-slots=heading, code
data-repeat=2
Syntax
public static void setSmallIconResourceID(int resourceID)
Example
MobileCore.setSmallIconResourceID(R.mipmap.ic_launcher_round);
setLargeIconResourceID
data-slots=heading, code
data-repeat=2
Syntax
public static void setLargeIconResourceID(int resourceID)
Example
MobileCore.setLargeIconResourceID(R.mipmap.ic_launcher_round);
setWrapperType
You can use the setWrapperType API to set the wrapper type when the SDK is being used in a cross-platform environment.
The wrapper type can be set to one of the follwing types: NONE, REACT_NATIVE, FLUTTER, CORDOVA, UNITY, XAMARIN.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void setWrapperType(@NonNull final WrapperType wrapperType)
Example
MobileCore.setWrapperType(WrapperType.REACT_NATIVE);
The wrapper type can be set to one of the follwing types: none, reactNative, flutter, cordova, unity, xamarin.
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
public static func setWrapperType(_ type: WrapperType)
Example
MobileCore.setWrapperType(.flutter)
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
@objc(setWrapperType:)
public static func setWrapperType(_ type: WrapperType)
Example
[AEPMobileCore setWrapperType:AEPWrapperTypeFlutter];
start
data-variant=warning
data-slots=text
MobileCore.start() API is no longer required when using MobileCore.registerExtensions().The start API triggers Mobile Core to start event processing. This should be used after the desired set of extensions have been registered using MobileCore.registerExtension() or <EXTENSION_NAME>.registerExtension(). A call to start will wait for any outstanding registrations to complete and then start event processing. You can use the callback to kickoff additional operations immediately after any operations kicked off during registration. This method should not be invoked more than once in your app.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public static void start(@Nullable final AdobeCallback<?> completionCallback)
Example
import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.Lifecycle;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Signal;
import com.adobe.marketing.mobile.UserProfile;
...
import android.app.Application;
...
public class MyApp extends Application {
...
@Override
public void onCreate(){
super.onCreate();
MobileCore.setApplication(this);
UserProfile.registerExtension();
Lifecycle.registerExtension();
Signal.registerExtension();
MobileCore.start(new AdobeCallback () {
@Override
public void call(Object o) {
// implement callback
}
});
}
}
trackAction
Actions are events that occur in your application. You can use the trackAction method 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 can use an action to track new subscriptions, every time an article is viewed, or every time a level is completed.
data-variant=warning
data-slots=text
trackAction method when you want to track an occurring event. In addition to the action name, you can also send context data with each trackAction call.data-variant=info
data-slots=text
Android Java
- action contains the name of the action to track.
- contextData contains the context data to attach on the hit.
data-slots=heading, code
data-repeat=2
Syntax
public static void trackAction(@NonNull final String action, @Nullable final Map<String, String> contextData)
Example
Map<String, String> additionalContextData = new HashMap<String, String>();
additionalContextData.put("customKey", "value");
MobileCore.trackAction("loginClicked", additionalContextData);
iOS Swift
- action contains the name of the action to track.
- contextData contains the context data to attach on this hit.
data-slots=heading, code
data-repeat=2
Syntax
static func track(action: String?, data: [String: Any]?)
Example
MobileCore.track(action: "action name", data: ["key": "value"])
iOS Objective-C
- action contains the name of the action to track.
- contextData contains the context data to attach on this hit.
data-slots=heading, code
data-repeat=2
Syntax
@objc(trackAction:data:)
static func track(action: String?, data: [String: Any]?)
Example
[AEPMobileCore trackAction:@"action name" data:@{@"key":@"value"}];
trackState
States represent screens or views in your application. The trackState method needs to be called every time a new state is displayed in your application. For example, this method should be called when a user navigates from the home page to the news feed. This method sends an Adobe Analytics state tracking hit with optional context data.
data-variant=info
data-slots=text
trackState method increments page views and an Adobe Analytics state tracking hit with the provided optional context data.Android Java
In Android, trackState is typically called every time a new Activity is loaded.
- state contains the name of the state to track.
- contextData contains the context data to attach on the hit.
data-slots=heading, code
data-repeat=2
Syntax
public static void trackState(@NonNull final String state, @Nullable final Map<String, String> contextData)
Example
Map<String, String> additionalContextData = new HashMap<String, String>();
additionalContextData.put("customKey", "value");
MobileCore.trackState("homePage", additionalContextData);
iOS Swift
- state contains the name of the state to track.
- contextData contains the context data to attach on this hit.
data-slots=heading, code
data-repeat=2
Syntax
static func track(state: String?, data: [String: Any]?)
Example
MobileCore.track(state: "state name", data: ["key": "value"])
iOS Objective-C
- state contains the name of the state to track.
- contextData contains the context data to attach on this hit.
data-slots=heading, code
data-repeat=2
Syntax
@objc(trackState:data:)
static func track(state: String?, data: [String: Any]?)
Example
[AEPMobileCore trackState:@"state name" data:@{@"key":@"value"}];
updateConfiguration
You can update the configuration programmatically by passing configuration keys and values to override the existing configuration using updateConfiguration API. For more information about configuration in Mobile Core, please refer to the Configuration API reference.
Public classes
AdobeCallback
The AdobeCallback class (Android) provides the interface to receive results when the asynchronous APIs perform the requested action.
Android Java
public interface AdobeCallback<T> {
void call(final T value);
}
AdobeCallbackWithError
The AdobeCallbackWithError class provides the interface to receive results or an error when the asynchronous APIs perform the requested action.
When using this class, if the request cannot be completed within the default timeout or an unexpected error occurs, the request is stopped and the fail method is called with the corresponding AdobeError or AEPError.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
public interface AdobeCallbackWithError<T> extends AdobeCallback<T> {
void fail(final AdobeError error);
}
Example
MobileCore.getPrivacyStatus(new AdobeCallbackWithError<MobilePrivacyStatus>() {
@Override
public void fail(final AdobeError error) {
if (error == AdobeError.UNEXPECTED_ERROR) {
// handle unexpected error
} else if (error == AdobeError.CALLBACK_TIMEOUT) {
// handle timeout error
} else if (error == AdobeError.CALLBACK_NULL) {
// handle null callback error
} else if (error == AdobeError.EXTENSION_NOT_INITIALIZED) {
// handle extension not initialized error
} else if (error == AdobeError.SERVER_ERROR) {
// handle server error
} else if (error == AdobeError.NETWORK_ERROR) {
// handle network error
} else if (error == AdobeError.INVALID_REQUEST) {
// handle invalid request error
} else if (error == AdobeError.INVALID_RESPONSE) {
// handle invalid response error
}
}
@Override
public void call(final MobilePrivacyStatus value) {
// use MobilePrivacyStatus value
}
});
iOS Swift
data-slots=heading, code
data-repeat=1
Example
MobileCore.getSdkIdentities { (content, error) in
if let error = error, let aepError = error as? AEPError {
switch aepError {
case .unexpected:
// Handle unexpected error
case .callbackTimeout:
// Handle callback timeout error
case .callbackNil:
// Handle callback being nil error
case .none:
// no error
case .serverError:
// handle server error
case .networkError:
// handle network error
case .invalidRequest:
// handle invalid request error
case .invalidResponse:
// handle invalid response error
case .errorExtensionNotInitialized:
// handle extension not initialized error
@unknown default:
// handle unknown error
}
}
...
}
iOS Objective-C
data-slots=heading, code
data-repeat=1
Example
[AEPMobileCore getSdkIdentities:^(NSString * _Nullable content, NSError * _Nullable error) {
if (error) {
if (error.code == AEPErrorUnexpected) {
// Handle unexpected error
} else if (error.code == AEPErrorCallbackTimeout) {
// Handle callback timeout error
} else if (error.code == AEPErrorCallbackNil) {
// Handle callback being nil error
} else if (error.code == AEPErrorNone) {
// no error
} else if (error.code == AEPErrorServerError) {
// handle server error
} else if (error.code == AEPErrorNetworkError) {
// handle network error
} else if (error.code == AEPErrorInvalidRequest) {
// handle invalid request error
} else if (error.code == AEPErrorInvalidResponse) {
// handle invalid response error
} else if (error.code == AEPErrorErrorExtensionNotInitialized) {
// handle extension not intialized error
}
}
...
}];
AdobeError
The AdobeError class (Android) shows the errors that can be passed to an AdobeCallbackWithError:
UNEXPECTED_ERROR- An unexpected error occurred.CALLBACK_TIMEOUT- The timeout was met.CALLBACK_NULL- The provided callback function is null.EXTENSION_NOT_INITIALIZED- The extension is not initialized.SERVER_ERROR- There was a server error.NETWORK_ERROR- There was a network error.INVALID_REQUEST- There was an invalid request.INVALID_RESPONSE- There was an invalid response.
AEPError
The AEPError enum (iOS) shows the errors that can be passed to a completion handler callback from any API which uses one:
case unexpected- An unexpected error occured.case callbackTimeout- The timeout was met.case callbackNil- The provided callback function is nil.case none- There was no error, used when an error return type is required but there was no error.case serverError- There was a server error.case networkError- There was a network error.case invalidRequest- There was an invalid request.case invalidResponse- There was an invalid response.case errorExtensionNotInitialized- The extension is not initialized.
InitOptions
The InitOptions class defines the options for initializing the AEP SDK. It currently supports the following options:
appID– The App ID used to retrieve remote configurations from Adobe servers.filePath– The location of a configuration file, either stored locally or within the application’s assets.lifecycleAutomaticTrackingEnabled– A boolean flag to enable or disable automatic lifecycle tracking (default: true).lifecycleAdditionalContextData– A map containing extra context data to be sent with the lifecycle start event.appGroup(iOS only) – A string representing the App Group identifier for sharing data between app extensions and the main application.
For usage details, refer to the InitOptions class on GitHub for Android and iOS.
Additional information
To learn what context data is, please read the documentation on context data.