| info |
SDK Version
|
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
}[[MoEngageSDKMessaging sharedInstance] logNotificationReceivedWithPayload:notification.request.content.userInfo completion: ^(void) {
// 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)
[[MoEngageSDKMessaging sharedInstance] logNotificationClickedWithPayload: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))
BOOL isPushFromMoEngage = [[MoEngageSDKMessaging sharedInstance] isPushFromMoEngageWithPayload:notification.request.content.userInfo];
Handling Background Updates (Self-Handled)
| library_add_check |
Prerequisites for iOS Background Updates
|
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.
| info |
Implementation Note Background updates must be handled in the |
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)
}
}- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// 1. Check if it's a MoEngage Background Update payload
if ([[MoEngageSDKMessaging sharedInstance] isSelfHandledBackgroundNotificationWithPayload:userInfo]) {
// 2. Log notification received impression manually
[[MoEngageSDKMessaging sharedInstance] logNotificationReceivedWithPayload:userInfo completion:^{
// 3. Execute your custom background logic here (e.g., sync data, logout)
// [self handleCustomBackgroundLogic:userInfo];
// 4. Always call the completion handler
completionHandler(UIBackgroundFetchResultNewData);
}];
} else {
// Handle standard MoEngage or other push notifications
[[MoEngageSDKMessaging sharedInstance] didReceieveNotificationInApplication:application withInfo:userInfo];
}
}