From 4d739c096ff95f55908d263f717d6217fce6e805 Mon Sep 17 00:00:00 2001 From: Ovidiu Cristescu <55203625+LunatiqueCoder@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:14:46 +0300 Subject: [PATCH] bug/#1109-#1096-remote-onForegroundEvent-getInitialNotification --- .../NotifeeCore+NSNotificationCenter.m | 19 ++++++++++++------- .../NotifeeCore+UNUserNotificationCenter.m | 15 +++------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m b/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m index 560a62ce..c0103678 100644 --- a/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m +++ b/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m @@ -58,13 +58,18 @@ + (void)load { #pragma mark Application Notifications - (void)application_onDidFinishLaunchingNotification:(nonnull NSNotification *)notification { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - UILocalNotification *launchNotification = - (UILocalNotification *)notification.userInfo[UIApplicationLaunchOptionsLocalNotificationKey]; - [[NotifeeCoreUNUserNotificationCenter instance] - onDidFinishLaunchingNotification:launchNotification.userInfo]; - [[NotifeeCoreUNUserNotificationCenter instance] getInitialNotification]; + NSDictionary *notifUserInfo = + notification.userInfo[UIApplicationLaunchOptionsLocalNotificationKey]; + + if (!notifUserInfo) { + // Fallback to remote notification key if local notification key is not available + notifUserInfo = notification.userInfo[UIApplicationLaunchOptionsRemoteNotificationKey]; + } + + if (notifUserInfo) { + [[NotifeeCoreUNUserNotificationCenter instance] onDidFinishLaunchingNotification:notifUserInfo]; + [[NotifeeCoreUNUserNotificationCenter instance] getInitialNotification]; + } [[NotifeeCoreUNUserNotificationCenter instance] observe]; } diff --git a/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m b/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m index beaa3600..dd2a0155 100644 --- a/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +++ b/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m @@ -21,7 +21,6 @@ #import "NotifeeCoreUtil.h" @implementation NotifeeCoreUNUserNotificationCenter - struct { unsigned int willPresentNotification : 1; unsigned int didReceiveNotificationResponse : 1; @@ -104,7 +103,6 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center NSDictionary *notifeeNotification = notification.request.content.userInfo[kNotifeeUserInfoNotification]; - // we only care about notifications created through notifee if (notifeeNotification != nil) { UNNotificationPresentationOptions presentationOptions = UNNotificationPresentationOptionNone; NSDictionary *foregroundPresentationOptions = @@ -148,23 +146,16 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center presentationOptions |= UNNotificationPresentationOptionAlert; } - NSDictionary *notifeeTrigger = notification.request.content.userInfo[kNotifeeUserInfoTrigger]; - if (notifeeTrigger != nil) { - // post DELIVERED event - [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:@{ + // post DELIVERED event + [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:@{ @"type" : @(NotifeeCoreEventTypeDelivered), @"detail" : @{ @"notification" : notifeeNotification, } - }]; - } + }]; completionHandler(presentationOptions); - } else if (_originalDelegate != nil && originalUNCDelegateRespondsTo.willPresentNotification) { - [_originalDelegate userNotificationCenter:center - willPresentNotification:notification - withCompletionHandler:completionHandler]; } }