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.
Copied to your clipboardfunc application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {MobileCore.setPushIdentifier(deviceToken)}
Copied to your clipboard- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {[AEPMobileCore setPushIdentifier:deviceToken];}
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(_:didReceive:withCompletionHandler:) method.
Copied to your clipboardfunc 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 itlet appHandlesUrl = falsereturn appHandlesUrl}, closure: { pushTrackingStatus inif pushTrackingStatus == .trackingInitiated {// tracking was successful} else {// tracking failed, view the status for more information}})completionHandler()}
Copied to your clipboard- (void) userNotificationCenter:(UNUserNotificationCenter *) centerdidReceiveNotificationResponse:(UNNotificationResponse *) responsewithCompletionHandler:(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 itbool appHandlesUrl = false;return appHandlesUrl;} closure:^(AEPPushTrackingStatus status) {if (status == AEPPushTrackingStatusTrackingInitiated) {// tracking was successful} else {// tracking failed, view the status for more information}}];}
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.
Copied to your clipboardMessaging.handleNotificationResponse(response) { trackingStatus in// handle the different values of trackingStatus}
Copied to your clipboard[AEPMobileMessaging handleNotificationResponse:response urlHandler:nil closure:^(AEPPushTrackingStatus status) {if (status == AEPPushTrackingStatusTrackingInitiated) {NSLog(@"Successfully started push notification tracking");}}];