Skip to main content
SDK Version
  • General Messaging: Supported from version 9.13.0
  • Background Updates (Self handled): Supported from version 10.10.0

Track Notification Received

Call SDK’s logNotificationReceived(withPayload: ) function to track notification received impression as shown below.
MoEngageSDKMessaging.sharedInstance.logNotificationReceived(withPayload:notification.request.content.userInfo) {
    // updated content in contentHandler here 
}

Track Notification Click

To track the notification clicked event using the payload, call the SDK’s logNotificationClicked function, as shown below.
MoEngageSDKMessaging.sharedInstance.logNotificationClicked(withPayload: notification.request.content.userInfo)
To accurately track clicks or dismissals, use the logNotificationClicked(withResponse: ) method.
MoEngageSDKMessaging.sharedInstance.logNotificationClicked(withResponse: UNNotificationResponse)
NoteTo use above functions, Appdelegate swizzling should be disabled. To see how to disable swizzling, please see the link.

Validate if the notification belongs to MoEngage

Call SDK’s isPushFromMoEngage(withPayload:) function to validate if the notification belongs to MoEngage as shown below:
 let isPushFromMoEngage = MoEngageSDKMessaging.sharedInstance.isPushFromMoEngage(withPayload: notification.request.content.userInfo))

Handling Background Updates (Self-Handled)

Prerequisites for iOS Background Updates
  • Background Modes: You must enable Remote notifications under the Signing & Capabilities tab in Xcode.
  • Payload Identifier: The SDK identifies these payloads by checking for nt: sh_b inside the moeFeatures dictionary.
The Background Update template allows you to send silent data payloads to your application. Because these notifications do not display a UI, the MoEngage SDK provides a specific helper method to identify them so you can execute custom background logic. For more information on the payload structure and available keys, refer to Background Update Templates.
Implementation NoteBackground updates must be handled in the didReceiveRemoteNotification fetch completion handler. You must also call logNotificationReceived manually to ensure these silent events are recorded in your analytics.
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

// 1. Check if it's a MoEngage Background Update payload
if MoEngageSDKMessaging.sharedInstance.isSelfHandledBackgroundNotification(payload: userInfo) {
    
    // 2. Log notification received impression manually
    MoEngageSDKMessaging.sharedInstance.logNotificationReceived(withPayload: userInfo) {
        
        // 3. Execute your custom background logic here (e.g., sync data, logout)
        // self.handleCustomBackgroundLogic(userInfo)
        
        // 4. Always call the completion handler
        completionHandler(.newData)
    }
} else {
    // Handle standard MoEngage or other push notifications
    MoEngageSDKMessaging.sharedInstance.didReceieveNotification(inApplication: application, withInfo: userInfo)
}


}