Push Notification - API reference

This document details how to use the APIs provided by the AEPMessaging framework for tracking and displaying push notifications.

Pre-requisites

Integrate and register AEPMessaging extension in your app.

Sync the push token

To retrieve the push token in iOS, refer to the Apple documentation for registering your app with APNs. Then add the following code to the application(_: didRegisterForRemoteNotificationsWithDeviceToken:) method in the AppDelegate to sync the device's push token with profile in Adobe Experience Platform.

data-slots=heading, code
data-repeat=2

Swift

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    MobileCore.setPushIdentifier(deviceToken)
}

Objective-C

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [AEPMobileCore setPushIdentifier:deviceToken];
}
data-variant=info
data-slots=text
Calling resetIdentities will clear the push token from the Mobile SDK. After calling resetIdentities, the push token must be re-synced using setPushIdentifier.

Track push notification interactions

Use handleNotificationResponse API to send push notification interaction data to Adobe Experience Platform.

In iOS, UNUserNotificationCenterDelegate is the interface for processing incoming notifications and responding to notification actions. Once the delegate is implemented, handle push notification responses in userNotificationCenter(_withCompletionHandler:) method.

data-slots=heading, code
data-repeat=2

Swift

func userNotificationCenter(_: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {

    Messaging.handleNotificationResponse(response, urlHandler: { url in
        /// return `true` if the app is handling the url or `false` if the Adobe SDK should handle it
        let appHandlesUrl = false
        return appHandlesUrl
    }, closure: { pushTrackingStatus in
        if pushTrackingStatus == .trackingInitiated {
            // tracking was successful
        } else {
            // tracking failed, view the status for more information
        }
    })

    completionHandler()
}

Objective-C

- (void) userNotificationCenter:(UNUserNotificationCenter *) center
 didReceiveNotificationResponse:(UNNotificationResponse *) response
         withCompletionHandler:(void (^)(void)) completionHandler {

    [AEPMobileMessaging handleNotificationResponse:response urlHandler: ^(NSURL *url) {
        /// return `true` if the app is handling the url or `false` if the Adobe SDK should handle it
        bool appHandlesUrl = false;
        return appHandlesUrl;
    } closure:^(AEPPushTrackingStatus status) {
        if (status == AEPPushTrackingStatusTrackingInitiated) {
            // tracking was successful
        } else {
            // tracking failed, view the status for more information
        }
    }];
}
data-variant=info
data-slots=text
This API method will automatically handle click behaviour defined for the push notification in Adobe Journey Optimizer.

Reading push tracking status

Implement the callback in handleNotificationResponse API to read PushTrackingStatus enum representing tracking status of the push notification.

data-slots=heading, code
data-repeat=2

Swift

Messaging.handleNotificationResponse(response) { trackingStatus in
    // handle the different values of trackingStatus
}

Objective-C

[AEPMobileMessaging handleNotificationResponse:response urlHandler:nil closure:^(AEPPushTrackingStatus status) {
    if (status == AEPPushTrackingStatusTrackingInitiated) {
        NSLog(@"Successfully started push notification tracking");
    }
}];