diff --git a/SampleApp/ios/SampleApp/AppDelegate.mm b/SampleApp/ios/SampleApp/AppDelegate.mm index 28455284..392a1f88 100644 --- a/SampleApp/ios/SampleApp/AppDelegate.mm +++ b/SampleApp/ios/SampleApp/AppDelegate.mm @@ -103,4 +103,29 @@ - (UISceneConfiguration *)application:(UIApplication *)application return config; } +#pragma mark - UNUserNotificationCenterDelegate +// +// Mirrors the canonical pattern in MoEngageTestApp/AppDelegate.swift:241-245 — forwards +// the notification to the MoEngage SDK for analytics + inbox + impression tracking, then +// tells iOS what to display in foreground via `completionHandler`. Without these methods +// iOS suppresses the foreground banner because the SDK's proxy default is `[]`. + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center + willPresentNotification:(UNNotification *)notification + withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { + [[MoEngageSDKMessaging sharedInstance] userNotificationCenter:center + willPresent:notification]; + completionHandler(UNNotificationPresentationOptionAlert + | UNNotificationPresentationOptionSound + | UNNotificationPresentationOptionBadge); +} + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center +didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void (^)(void))completionHandler { + [[MoEngageSDKMessaging sharedInstance] userNotificationCenter:center + didReceive:response]; + completionHandler(); +} + @end diff --git a/SampleApp/ios/SampleSwiftApp/AppDelegate.swift b/SampleApp/ios/SampleSwiftApp/AppDelegate.swift index c211626c..81fbab5d 100644 --- a/SampleApp/ios/SampleSwiftApp/AppDelegate.swift +++ b/SampleApp/ios/SampleSwiftApp/AppDelegate.swift @@ -98,3 +98,30 @@ class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate { #endif } } + +// MARK: - UNUserNotificationCenterDelegate +// +// Mirrors the canonical pattern in MoEngageTestApp/AppDelegate.swift:241-245 — forwards +// the notification to the MoEngage SDK for analytics + inbox + impression tracking, then +// tells iOS what to display in foreground via `completionHandler`. Without these methods +// iOS suppresses the foreground banner because the SDK's proxy default is `[]`. +extension AppDelegate { + + func userNotificationCenter( + _ center: UNUserNotificationCenter, + willPresent notification: UNNotification, + withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void + ) { + MoEngageSDKMessaging.sharedInstance.userNotificationCenter(center, willPresent: notification) + completionHandler([.alert, .sound, .badge]) + } + + func userNotificationCenter( + _ center: UNUserNotificationCenter, + didReceive response: UNNotificationResponse, + withCompletionHandler completionHandler: @escaping () -> Void + ) { + MoEngageSDKMessaging.sharedInstance.userNotificationCenter(center, didReceive: response) + completionHandler() + } +}