Adobe Campaign Classic API reference
extensionVersion
The extensionVersion
API returns the version of the Campaign Classic extension that is registered with the Mobile Core extension.
Swift
Syntax
Copied to your clipboardstatic var extensionVersion: String
Example
Copied to your clipboardlet campaignClassicVersion = CampaignClassic.extensionVersion
Objective-C
Syntax
Copied to your clipboard+ (nonnull NSString *)extensionVersion
Example
Copied to your clipboardNSString *campaignClassicVersion = [AEPMobileCampaignClassic extensionVersion];
Java
Syntax
Copied to your clipboard@NonNullpublic static String extensionVersion();
Example
Copied to your clipboardString campaignClassicExtensionVersion = CampaignClassic.extensionVersion();
Swift
Syntax
Copied to your clipboardstatic var extensionVersion: String
Example
Copied to your clipboardlet campaignClassicVersion = CampaignClassic.extensionVersion
Objective-C
Syntax
Copied to your clipboard+ (nonnull NSString *)extensionVersion
Example
Copied to your clipboardNSString *campaignClassicVersion = [AEPMobileCampaignClassic extensionVersion];
registerDevice
The registerDevice
API lets you register a user device with Campaign Classic.
To prepare your app to handle push notifications, see the tutorial on setting up a Firebase Cloud Messaging client app on Android. After you receive the Firebase Cloud Messaging (FCM) SDK registration token, send this token and the device information to Campaign Classic by using the registerDevice
API.
The registerDevice
API registers a device with your Campaign Classic registration server. It takes the FCM registration token as a parameter with a user key that identifies a user, such as an email address or a login name. You can also provide a map of the custom key-value pairs that you want to associate with the registration.
Java
Syntax
Copied to your clipboardpublic static void registerDevice(@NonNull final String token, final String userKey, final Map<String, Object> additionalParams)
Example
Copied to your clipboard@Overridepublic void onNewToken(String token) {Log.d("TestApp", "Refreshed token: " + token);// If you want to send messages to this application instance or// manage this app's subscriptions on the server side, send the// Instance ID token to your app server.if (token != null) {Log.d("TestApp", "FCM SDK registration token received : " + token);// Create a map of additional parametersMap<String, Object> additionalParams = new HashMap<String, Object>();additionalParams.put("name", "John");additionalParams.put("serial", 12345);additionalParams.put("premium", true);// Send the registration infoCampaignClassic.registerDevice(token, "john@example.com", additionalParams);}}
To get your app ready to handle push notifications, see the tutorial on configuring remote notification support. After you receive the Apple Push Notification service (APNs) token, send this token and the device information to Campaign Classic using the registerDevice
API.
The registerDevice
API registers a device with your Campaign Classic registration server. It takes the APNS token as a parameter with a user key that identifies a user, such as an email address or a login name. You can also provide a map of the custom key-value pairs that you want to associate with the registration.
Swift
Syntax
Copied to your clipboardstatic func registerDevice(token: Data, userKey: String?, additionalParameters: [String: Any]?)
Example
Copied to your clipboardfunc application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {let params: [String: Any] = ["name": "John","serial": 12345,"premium": true]CampaignClassic.registerDevice(token: deviceToken, userKey: "johnDoe@example.com", additionalParameters: params)}
Objective-C
Syntax
Copied to your clipboard+ (void) registerDeviceWithToken:(nonnull NSData*)token userKey:(nullable NSString*)userKey additionalParams:(nullable NSDictionary<NSString *, id> *)additionalParams;
Example
Copied to your clipboard- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys: @"John", @"name", nil];[params setObject: [NSNumber numberWithInt:12345] forKey: @"serial"];[params setObject: [NSNumber numberWithBool:YES] forKey: @"premium"];[AEPMobileCampaignClassic registerDeviceWithToken:deviceToken userKey:@"john@example.com" additionalParameters:params];}
To prepare your app to handle push notifications, see the tutorial on setting up a Firebase Cloud Messaging client app on Android. After you receive the Firebase Cloud Messaging (FCM) SDK registration token, send this token and the device information to Campaign Classic by using the registerDevice
API.
The registerDevice
API registers a device with your Campaign Classic registration server. It takes the FCM registration token as a parameter with a user key that identifies a user, such as an email address or a login name. You can also provide a map of the custom key-value pairs that you want to associate with the registration.
Java
Syntax
Copied to your clipboardpublic static void registerDevice(@NonNull final String token, final String userKey, final Map<String, Object> additionalParams)
Example
Copied to your clipboard@Overridepublic void onNewToken(String token) {Log.d("TestApp", "Refreshed token: " + token);// If you want to send messages to this application instance or// manage this app's subscriptions on the server side, send the// Instance ID token to your app server.if (token != null) {Log.d("TestApp", "FCM SDK registration token received : " + token);// Create a map of additional parametersMap<String, Object> additionalParams = new HashMap<String, Object>();additionalParams.put("name", "John");additionalParams.put("serial", 12345);additionalParams.put("premium", true);// Send the registration infoCampaignClassic.registerDevice(token, "john@example.com", additionalParams);}}
To get your app ready to handle push notifications, see the tutorial on configuring remote notification support. After you receive the Apple Push Notification service (APNs) token, send this token and the device information to Campaign Classic using the registerDevice
API.
The registerDevice
API registers a device with your Campaign Classic registration server. It takes the APNS token as a parameter with a user key that identifies a user, such as an email address or a login name. You can also provide a map of the custom key-value pairs that you want to associate with the registration.
Swift
Syntax
Copied to your clipboardstatic func registerDevice(token: Data, userKey: String?, additionalParameters: [String: Any]?)
Example
Copied to your clipboardfunc application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {let params: [String: Any] = ["name": "John","serial": 12345,"premium": true]CampaignClassic.registerDevice(token: deviceToken, userKey: "johnDoe@example.com", additionalParameters: params)}
Objective-C
Syntax
Copied to your clipboard+ (void) registerDeviceWithToken:(nonnull NSData*)token userKey:(nullable NSString*)userKey additionalParams:(nullable NSDictionary<NSString *, id> *)additionalParams;
Example
Copied to your clipboard- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys: @"John", @"name", nil];[params setObject: [NSNumber numberWithInt:12345] forKey: @"serial"];[params setObject: [NSNumber numberWithBool:YES] forKey: @"premium"];[AEPMobileCampaignClassic registerDeviceWithToken:deviceToken userKey:@"john@example.com" additionalParameters:params];}
registerExtension
This API has been deprecated starting in v2.0.0 and removed in v3.0.0 of the Android mobile extension.
Use MobileCore.registerExtensions()
API instead.
trackNotificationReceive
The trackNotificationReceive
API sends the received push notification's tracking information to the configured Adobe Campaign Classic server.
If you are using the AEPMessagingService.handleRemoteMessage
API, you should not call CampaignClassic.trackNotificationReceive
or CampaignClassic.trackNotificationClick
.
Java
If trackInfo
is null or does not contain the necessary tracking identifiers, messageId
(_mId
) and deliveryId
(_dId
), a track request is not sent.
Syntax
Copied to your clipboardpublic static void trackNotificationReceive(@NonNull final Map<String, String> trackInfo)
Example
Copied to your clipboardpublic class MyFirebaseMessagingService extends FirebaseMessagingService {@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {Log.d("TestApp", "Receive message from: " + remoteMessage.getFrom());Map<String,String> payloadData = message.getData();// Check if message contains data payload.if (payloadData.size() > 0) {Map<String,String> trackInfo = new HashMap<>();trackInfo.put("_mId", payloadData.get("_mId"));trackInfo.put("_dId", payloadData.get("_dId"));// Send the tracking information for message receivedCampaignClassic.trackNotificationReceive(trackInfo);}}}
You can pass the launchOptions
that were received upon opening the application or userInfo
, which contains the received push payload in userInfo
. If userInfo
is null or does not contain the necessary tracking identifiers, broadlogId
(_mId
) and deliveryId
(_dId
), a track request is not sent.
Swift
Syntax
Copied to your clipboardstatic func trackNotificationReceive(withUserInfo userInfo: [AnyHashable: Any])
Example
Copied to your clipboardfunc application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {guard let aps = userInfo["aps"] as? [String: Any] else {completionHandler(.failed)return}if aps["content-available"] as? Int == 1 {// Track silent push notification receiveCampaignClassic.trackNotificationReceive(withUserInfo: userInfo)completionHandler(.noData)}}
Objective-C
Syntax
Copied to your clipboard+ (void) trackNotificationReceiveWithUserInfo:(nonnull NSDictionary*) userInfo;
Example
Copied to your clipboard- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)launchOptions fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{if ( launchOptions) NSLog(@"launchOptions: %@", [launchOptions description]);// Tracking silent push notification receiveif ( [launchOptions[@"aps"][@"content-available"] intValue] == 1 ) {NSLog(@"Silent Push Notification");[AEPMobileCampaignClassic trackNotificationReceiveWithUserInfo:userInfo];completionHandler(UIBackgroundFetchResultNoData);}}
Java
If trackInfo
is null or does not contain the necessary tracking identifiers, messageId
(_mId
) and deliveryId
(_dId
), a track request is not sent.
Syntax
Copied to your clipboardpublic static void trackNotificationReceive(@NonNull final Map<String, String> trackInfo)
Example
Copied to your clipboardpublic class MyFirebaseMessagingService extends FirebaseMessagingService {@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {Log.d("TestApp", "Receive message from: " + remoteMessage.getFrom());Map<String,String> payloadData = message.getData();// Check if message contains data payload.if (payloadData.size() > 0) {Map<String,String> trackInfo = new HashMap<>();trackInfo.put("_mId", payloadData.get("_mId"));trackInfo.put("_dId", payloadData.get("_dId"));// Send the tracking information for message receivedCampaignClassic.trackNotificationReceive(trackInfo);}}}
You can pass the launchOptions
that were received upon opening the application or userInfo
, which contains the received push payload in userInfo
. If userInfo
is null or does not contain the necessary tracking identifiers, broadlogId
(_mId
) and deliveryId
(_dId
), a track request is not sent.
Swift
Syntax
Copied to your clipboardstatic func trackNotificationReceive(withUserInfo userInfo: [AnyHashable: Any])
Example
Copied to your clipboardfunc application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {guard let aps = userInfo["aps"] as? [String: Any] else {completionHandler(.failed)return}if aps["content-available"] as? Int == 1 {// Track silent push notification receiveCampaignClassic.trackNotificationReceive(withUserInfo: userInfo)completionHandler(.noData)}}
Objective-C
Syntax
Copied to your clipboard+ (void) trackNotificationReceiveWithUserInfo:(nonnull NSDictionary*) userInfo;
Example
Copied to your clipboard- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)launchOptions fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{if ( launchOptions) NSLog(@"launchOptions: %@", [launchOptions description]);// Tracking silent push notification receiveif ( [launchOptions[@"aps"][@"content-available"] intValue] == 1 ) {NSLog(@"Silent Push Notification");[AEPMobileCampaignClassic trackNotificationReceiveWithUserInfo:userInfo];completionHandler(UIBackgroundFetchResultNoData);}}
trackNotificationClick
The trackNotificationClick
API sends the clicked push notification's tracking information to the configured Adobe Campaign Classic server. This API can be used to send tracking information when the notification is clicked, which may result in the application being opened.
If you are using the AEPMessagingService.handleRemoteMessage
API, you should not call CampaignClassic.trackNotificationReceive
or CampaignClassic.trackNotificationClick
.
Java
If trackInfo
is null, or does not contain the necessary tracking identifiers, messageId
(_mId
) and deliveryId
(_dId
), a track request is not sent.
Syntax
Copied to your clipboardpublic static void trackNotificationClick(@NonNull final Map<String, String> trackInfo)
Example
Copied to your clipboard@Overridepublic void onResume() {super.onResume();// The messageId (_mId) and deliveryId (_dId) can be passed in the intent extras.// This is assuming you extract the messageId and deliveryId from the// received push message and are including it in the intent (intent.putExtra())// of the displayed notification.Bundle extras = getIntent().getExtras();if (extras != null) {String deliveryId = extras.getString("_dId");String messageId = extras.getString("_mId");if (deliveryId != null && messageId != null) {Map<String,String> trackInfo = new HashMap<>();trackInfo.put("_mId", messageId);trackInfo.put("_dId", deliveryId);// Send the tracking information for message openingCampaignClassic.trackNotificationClick(trackInfo);}}}
You can pass the launchOptions
that were received upon opening the application or userInfo
, which contains the received push payload in userInfo
. If userInfo
is null or does not contain the necessary tracking identifiers, broadlogId
(_mId
) and deliveryId
(_dId
), a track request is not sent.
Swift
Syntax
Copied to your clipboardstatic func trackNotificationClick(withUserInfo userInfo: [AnyHashable: Any])
Example
Copied to your clipboardfunc userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {CampaignClassic.trackNotificationClick(withUserInfo: response.notification.request.content.userInfo)}
Objective-C
Syntax
Copied to your clipboard+ (void) trackNotificationClickWithUserInfo: (nonnull NSDictionary*) userInfo;
Example
Copied to your clipboard- (void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler{NSDictionary *userInfo = response.notification.request.content.userInfo;[AEPMobileCampaignClassic trackNotificationClickWithUserInfo:userInfo];completionHandler();}
Java
If trackInfo
is null, or does not contain the necessary tracking identifiers, messageId
(_mId
) and deliveryId
(_dId
), a track request is not sent.
Syntax
Copied to your clipboardpublic static void trackNotificationClick(@NonNull final Map<String, String> trackInfo)
Example
Copied to your clipboard@Overridepublic void onResume() {super.onResume();// The messageId (_mId) and deliveryId (_dId) can be passed in the intent extras.// This is assuming you extract the messageId and deliveryId from the// received push message and are including it in the intent (intent.putExtra())// of the displayed notification.Bundle extras = getIntent().getExtras();if (extras != null) {String deliveryId = extras.getString("_dId");String messageId = extras.getString("_mId");if (deliveryId != null && messageId != null) {Map<String,String> trackInfo = new HashMap<>();trackInfo.put("_mId", messageId);trackInfo.put("_dId", deliveryId);// Send the tracking information for message openingCampaignClassic.trackNotificationClick(trackInfo);}}}
You can pass the launchOptions
that were received upon opening the application or userInfo
, which contains the received push payload in userInfo
. If userInfo
is null or does not contain the necessary tracking identifiers, broadlogId
(_mId
) and deliveryId
(_dId
), a track request is not sent.
Swift
Syntax
Copied to your clipboardstatic func trackNotificationClick(withUserInfo userInfo: [AnyHashable: Any])
Example
Copied to your clipboardfunc userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {CampaignClassic.trackNotificationClick(withUserInfo: response.notification.request.content.userInfo)}
Objective-C
Syntax
Copied to your clipboard+ (void) trackNotificationClickWithUserInfo: (nonnull NSDictionary*) userInfo;
Example
Copied to your clipboard- (void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler{NSDictionary *userInfo = response.notification.request.content.userInfo;[AEPMobileCampaignClassic trackNotificationClickWithUserInfo:userInfo];completionHandler();}
Other public classes
Push template functionality and the following public classes are only available in Adobe Campaign Classic Android SDK version from 2.1.0 through the next major version release.
AEPMessagingService
handleRemoteMessage
Allows the Adobe Campaign Classic extension to automatically create and dispatch a Notification
based on the template included in the provided RemoteMessage
object.
If you are using the AEPMessagingService.handleRemoteMessage
API, you should not call CampaignClassic.trackNotificationReceive
or CampaignClassic.trackNotificationClick
.
Android
Requires extension version v2.1.0 through the next major version release
Builds an AEPPushPayload
with data extracted from a RemoteMessage
's payload. The built AEPPushPayload
is then used to construct a Notification
.
Java
Syntax
Copied to your clipboard@NonNullpublic static boolean handleRemoteMessage(@NonNull final Context context, @NonNull final RemoteMessage remoteMessage);
Example
Copied to your clipboard@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {Log.d(LOG_TAG, "From: " + remoteMessage.getFrom());if (AEPMessagingService.handleRemoteMessage(this, remoteMessage)) {// Campaign extension has handled the notification} else {// Handle notification from other sources}}
Requires extension version v2.1.0 through the next major version release
Builds an AEPPushPayload
with data extracted from a RemoteMessage
's payload. The built AEPPushPayload
is then used to construct a Notification
.
Java
Syntax
Copied to your clipboard@NonNullpublic static boolean handleRemoteMessage(@NonNull final Context context, @NonNull final RemoteMessage remoteMessage);
Example
Copied to your clipboard@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {Log.d(LOG_TAG, "From: " + remoteMessage.getFrom());if (AEPMessagingService.handleRemoteMessage(this, remoteMessage)) {// Campaign extension has handled the notification} else {// Handle notification from other sources}}
AEPPushTemplateBroadcastReceiver
This class is required to be public, but has no APIs that need to be called by the app developer.
CampaignPushTrackerActivity
This class is required to be public, but has no APIs that need to be called by the app developer.