Push Payload Receivers

Handling Push Notification Click Events in iOS with Netmera SDK

Netmera SDK automatically collects Click Push Events, allowing you to track when users interact with notifications. However, if you experience issues with collecting these events, it’s important to ensure that your app is properly configured to handle them.

Implementing UNUserNotificationCenter Delegate

Set up the UNUserNotificationCenter.delegate at the beginning of the didFinishLaunchingWithOptions method in your AppDelegate file.

// In didFinishLaunchingWithOptions (AppDelegate.swift)
if #available(iOS 10.0, *) {
    UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
} else {
    // Fallback on earlier versions
}

Handle Push Notification Click Events

Once you’ve set the delegate, Netmera will automatically handle push notification events, including click events. Below are the methods to process push notification click events.

func userNotificationCenter(
    _ center: UNUserNotificationCenter, 
    didReceive response: UNNotificationResponse, 
    withCompletionHandler completionHandler: @escaping () -> Void
) {
    // NetmeraPushObject(dictionary: response.notification.request.content.userInfo)
    // object.alert.body                  // Push Text
    // object.alert.title                 // Push Title
    // object.action.deeplinkURL          // Push Deeplink
    // object.customDictionary            // Custom JSON
}

Push Notification Received

To capture push notifications when the app is in the background or foreground, you can implement the following methods. This method will return latest push object received by device.

func application(
    _ application: UIApplication, 
    didReceiveRemoteNotification userInfo: [AnyHashable: Any], 
    fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
    // Netmera.recentPushObject()?.alert.body                  // Push Text
    // Netmera.recentPushObject()?.alert.title                 // Push Title
    // Netmera.recentPushObject()?.action.deeplinkURL          // Push Deeplink
    // Netmera.recentPushObject()?.customDictionary            // Custom JSON
}

Push Notification Received on Foreground

This method allows you to handle push notifications when the app is in the foreground.

func userNotificationCenter(
    _ center: UNUserNotificationCenter, 
    willPresent notification: UNNotification, 
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
    completionHandler(.alert)
}

Retrieve Device Push Token

To get the push token, use the following method:

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

Last updated

Was this helpful?