Netmera Developer Guide
Netmera Docs
  • Netmera Developer Guide
  • Platforms
    • iOS
      • New iOS (Swift)
        • SDK Integration
        • Push Notifications
          • Delegate Methods
          • Widget and In-App Messages
          • Media Push
          • Carousel, Slider and Thumbnail Push
        • Deep Linking
          • Custom Deep Links
        • Sound & Vibration
        • Push Inbox
        • Events
        • Geofence & Location
        • User Attributes & Preferences
        • Advertising ID
        • Changelog
      • Former iOS (Objective-C)
        • SDK Integration
        • Push Notifications
          • Delegate Methods
          • Push Payload Receivers
          • Widget and In-App Messages
          • Customizing In-App Messages
          • Media Push
          • Carousel, Slider and Thumbnail Push
          • Custom Web View Presentation
          • Push Icon
        • Live Activities
        • Deep Linking
          • Custom Deep Links
        • Sound & Vibration
        • Push Inbox
        • Events
        • Geofence & Location
        • User Attributes & Preferences
        • Data Transfer
        • Advertising ID
        • SSL Pinning
        • Changelog
    • Android
      • SDK Integration
        • Huawei Integration
        • Huawei Message Receipt
        • Android Integration FAQs
      • Push Notifications
        • Widget and In-App Messages
        • Push Callbacks
        • Custom Web View Presentation
        • Push Icon
      • Deep Linking
        • Custom Deep Links
      • Sound & Vibration
      • Push Inbox
      • Events
      • Geofence & Location
        • Background Location Permission
      • User & Attributes
      • Data Transfer
      • Advertising ID
      • App Tracking
      • SSL Pinning
      • Changelog
    • Web
      • SDK Setup
        • Self-Hosted SDK Setup
      • Mobile Web Push for iOS
      • Deep Linking
        • Custom Deep Links
      • Events
      • User & Attributes
    • React Native
      • SDK Integration
      • Push Notifications
        • Widget and In-App Messages
        • Push Callbacks
      • Deep Linking
        • Custom Deep Links
      • Sound & Vibration
      • Push Inbox
      • Events
      • Geofence & Location
      • User & Attributes
      • Changelog
    • Flutter
      • SDK Integration
      • Push Notifications
        • Push Notification Permissions
        • Widget and In-App Messages
        • Flutter iOS Media Push
      • Deep Linking
        • Custom Deep Links
      • Sound & Vibration
      • Push Inbox
      • Events
      • Geofence & Location
      • User & Attributes
      • SSL Pinning
      • Changelog
    • Cordova
      • SDK Integration
      • Push Notifications
      • Sound & Vibration
      • Push Inbox
      • Events
      • User & Attributes
    • Unity
      • SDK Integration
      • Sound & Vibration
      • Events
      • User & Attributes
      • Changelog
  • Integrated Modules
    • Optimove
    • Adjust
    • Mixpanel
    • IYS Integration
    • VIA Integration
      • Short URL Consent Requests
      • OTP Consent Requests
        • OTP Confirmation Completion
      • VIA Email Rejection Link Generation
      • ETK Rejection via SMS
  • API Documentation
    • REST API
      • Setup
      • Notifications
      • Events
      • User & Device Management
      • Inbox Feature
      • GDPR
      • Error Responses
  • FAQs
    • Push Notifications FAQs
Powered by GitBook
On this page
  • Handling Push Notification Click Events in iOS with Netmera SDK
  • Implementing UNUserNotificationCenter Delegate
  • Handle Push Notification Click Events
  • Push Notification Received
  • Push Notification Received on Foreground
  • Retrieve Device Push Token

Was this helpful?

  1. Platforms
  2. iOS
  3. Former iOS (Objective-C)
  4. Push Notifications

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
}
// In didFinishLaunchingWithOptions (AppDelegate.m)
[UNUserNotificationCenter currentNotificationCenter].delegate = self;

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
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
  didReceiveNotificationResponse:(UNNotificationResponse *)response 
            withCompletionHandler:(void (^)(void))completionHandler
{
    // NetmeraPushObject *object = [[NetmeraPushObject alloc] initWithDictionary: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
}
- (void)application:(UIApplication *)application 
  didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    // [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)
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
  willPresentNotification:(UNNotification *)notification 
  withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
    completionHandler(UNNotificationPresentationOptionAlert);
}

Retrieve Device Push Token

To get the push token, use the following method:

func application(
    _ application: UIApplication, 
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
}
- (void)application:(UIApplication *)application 
  didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
}
PreviousDelegate MethodsNextWidget and In-App Messages

Last updated 2 months ago

Was this helpful?