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 1/4] 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]; } } From 4a8d50bd814971a7cfb46928603913f9ddb4ad1b 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 2/4] fix(ios): Remote issues: #1109-#1096 onForegroundEvent() and 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]; } } From 08c0f47ae8ec3effec25537214e7888c4bc2247d Mon Sep 17 00:00:00 2001 From: Ovidiu Cristescu <55203625+LunatiqueCoder@users.noreply.github.com> Date: Wed, 9 Oct 2024 02:37:20 +0300 Subject: [PATCH 3/4] bug/#1109-#1096-remote-onForegroundEvent-getInitialNotification - call onForegroundEvent() when app starts from terminated state - same as getInitialNotification() --- .../NotifeeCore+UNUserNotificationCenter.m | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m b/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m index dd2a0155..1bd7d002 100644 --- a/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +++ b/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m @@ -72,12 +72,31 @@ - (void)onDidFinishLaunchingNotification:(nonnull NSDictionary *)notifUserInfo { - (nullable NSDictionary *)getInitialNotification { if (_initialNotificationGathered && _initialNotificationBlock != nil) { + // copying initial notification if (_initialNotification != nil && [_initialNoticationID isEqualToString:_notificationOpenedAppID]) { - NSDictionary *initialNotificationCopy = [_initialNotification copy]; + + NSMutableDictionary *event = [NSMutableDictionary dictionary]; + NSMutableDictionary *initialNotificationCopy = [_initialNotification mutableCopy]; + initialNotificationCopy[@"initialNotification"] = @1; + _initialNotification = nil; + + // Runs getInitialNotification() on JavaScript side with payload: _initialNotificationBlock(nil, initialNotificationCopy); + + // Prepare onForegroundEvent() payload + event[@"detail"] = [initialNotificationCopy copy]; + if ([event[@"detail"][@"pressAction"][@"id"] isEqualToString:@"default"]) { + event[@"type"] = @1; // PRESS + } else { + event[@"type"] = @2; // ACTION_PRESS + } + + // Call onForegroundEvent() on Javascript side with payload: + [[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:event]; + } else { _initialNotificationBlock(nil, nil); } From 103447ec84aa900a27fcbeff3e97a8abc9319aff Mon Sep 17 00:00:00 2001 From: Ovidiu Cristescu <55203625+LunatiqueCoder@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:12:25 +0300 Subject: [PATCH 4/4] bug/#1109-#1096-remote-onForegroundEvent- update explanatory comment --- ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m b/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m index 1bd7d002..cb1710f2 100644 --- a/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +++ b/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m @@ -83,7 +83,7 @@ - (nullable NSDictionary *)getInitialNotification { _initialNotification = nil; - // Runs getInitialNotification() on JavaScript side with payload: + // Sets the return payload for getInitialNotification() _initialNotificationBlock(nil, initialNotificationCopy); // Prepare onForegroundEvent() payload