@@ -35,14 +35,14 @@ of this software and associated documentation files (the "Software"), to deal
3535#import " UNUserNotificationCenter+OneSignalNotifications.h"
3636#import " UIApplicationDelegate+OneSignalNotifications.h"
3737
38- @implementation OSNotificationOpenedResult
39- @synthesize notification = _notification, action = _action ;
38+ @implementation OSNotificationClickEvent
39+ @synthesize notification = _notification, result = _result ;
4040
41- - (id )initWithNotification : (OSNotification*)notification action : (OSNotificationAction*) action {
41+ - (id )initWithNotification : (OSNotification*)notification result : (OSNotificationClickResult*) result {
4242 self = [super init ];
4343 if (self) {
4444 _notification = notification;
45- _action = action ;
45+ _result = result ;
4646 }
4747 return self;
4848}
@@ -63,25 +63,24 @@ - (NSDictionary *_Nonnull)jsonRepresentation {
6363 error: &jsonError];
6464
6565 NSMutableDictionary * obj = [NSMutableDictionary new ];
66- NSMutableDictionary * action = [NSMutableDictionary new ];
67- [action setObject: self .action.actionId forKeyedSubscript: @" actionID" ];
68- [obj setObject: action forKeyedSubscript: @" action" ];
66+ NSMutableDictionary * result = [NSMutableDictionary new ];
67+ [result setObject: self .result.actionId forKeyedSubscript: @" actionID" ];
68+ [result setObject: self .result.url forKeyedSubscript: @" url" ];
69+ [obj setObject: result forKeyedSubscript: @" result" ];
6970 [obj setObject: notifDict forKeyedSubscript: @" notification" ];
70- if (self.action .type )
71- [obj[@" action" ] setObject: @(self .action.type) forKeyedSubscript: @" type" ];
72-
71+
7372 return obj;
7473}
7574
7675@end
7776
78- @implementation OSNotificationAction
79- @synthesize type = _type , actionId = _actionId;
77+ @implementation OSNotificationClickResult
78+ @synthesize url = _url , actionId = _actionId;
8079
81- -(id )initWithActionType : (OSNotificationActionType) type : (NSString *)actionID {
80+ -(id )initWithUrl : ( NSString *) url : (NSString *)actionID {
8281 self = [super init ];
8382 if (self) {
84- _type = type ;
83+ _url = url ;
8584 _actionId = actionID;
8685 }
8786 return self;
@@ -149,8 +148,14 @@ + (void)setLifecycleListener:(id<OSNotificationLifecycleListener>)lifecycleListe
149148
150149static int mSubscriptionStatus = -1 ;
151150
152- static NSMutableArray <OSNotificationOpenedResult*> *_unprocessedOpenedNotifis;
153- static OSNotificationOpenedBlock _notificationOpenedHandler;
151+ static NSMutableArray <OSNotificationClickEvent*> *_unprocessedClickEvents;
152+ static NSMutableArray <NSObject <OSNotificationClickListener> *> *_clickListeners;
153+ + (NSMutableArray <NSObject <OSNotificationClickListener> *>*)clickListeners {
154+ if (!_clickListeners)
155+ _clickListeners = [NSMutableArray new ];
156+ return _clickListeners;
157+ }
158+
154159static NSDictionary * _lastMessageReceived;
155160static NSString *_lastMessageID = @" " ;
156161static NSString *_lastMessageIdFromAction;
@@ -255,7 +260,7 @@ + (void)resetLocals {
255260 _lastMessageReceived = nil ;
256261 _lastMessageIdFromAction = nil ;
257262 _lastMessageID = @" " ;
258- _unprocessedOpenedNotifis = nil ;
263+ _unprocessedClickEvents = nil ;
259264}
260265
261266+ (void )setLastPermissionState : (OSPermissionStateInternal *)lastPermissionState {
@@ -693,7 +698,7 @@ + (void)handleNotificationOpened:(NSDictionary*)messageDict
693698// [[OSSessionManager sharedSessionManager] onDirectInfluenceFromNotificationOpen:_appEntryState withNotificationId:messageId];
694699// }
695700
696- [self handleNotificationAction: actionType actionID: actionID];
701+ [self handleNotificationActionWithUrl: notification.launchURL actionID: actionID];
697702}
698703
699704+ (void )submitNotificationOpened : (NSString *)messageId {
@@ -793,28 +798,35 @@ + (BOOL)handleIAMPreview:(OSNotification *)notification {
793798 return NO ;
794799}
795800
796- + (void )handleNotificationAction : (OSNotificationActionType) actionType actionID : (NSString *)actionID {
801+ + (void )handleNotificationActionWithUrl : ( NSString *) url actionID : (NSString *)actionID {
797802 if (![OneSignalCoreHelper isOneSignalPayload: _lastMessageReceived])
798803 return ;
799804
800- OSNotificationAction *action = [[OSNotificationAction alloc ] initWithActionType: actionType :actionID];
805+ OSNotificationClickResult *result = [[OSNotificationClickResult alloc ] initWithUrl: url :actionID];
801806 OSNotification *notification = [OSNotification parseWithApns: _lastMessageReceived];
802- OSNotificationOpenedResult *result = [[OSNotificationOpenedResult alloc ] initWithNotification: notification action: action ];
807+ OSNotificationClickEvent *event = [[OSNotificationClickEvent alloc ] initWithNotification: notification result: result ];
803808
804809 // Prevent duplicate calls to same action
805810 if ([notification.notificationId isEqualToString: _lastMessageIdFromAction])
806811 return ;
807812 _lastMessageIdFromAction = notification.notificationId ;
808813
809- [OneSignalTrackFirebaseAnalytics trackOpenEvent: result ];
810-
811- if (!_notificationOpenedHandler ) {
812- [self addUnprocessedOpenedNotifi: result ];
814+ [OneSignalTrackFirebaseAnalytics trackOpenEvent: event ];
815+
816+ if (self. clickListeners . count == 0 ) {
817+ [self addUnprocessedClickEvent: event ];
813818 return ;
814819 }
815- _notificationOpenedHandler (result) ;
820+ [ self fireClickListenersForEvent: event] ;
816821}
817822
823+ + (void )fireClickListenersForEvent : (OSNotificationClickEvent*)event {
824+ for (NSObject <OSNotificationClickListener> *listener in self.clickListeners ) {
825+ if ([listener respondsToSelector: @selector (onClickNotification: )]) {
826+ [listener onClickNotification: event];
827+ }
828+ }
829+ }
818830
819831+ (void )lastMessageReceived : (NSDictionary *)message {
820832 _lastMessageReceived = message;
@@ -828,11 +840,15 @@ + (BOOL)shouldSuppressURL {
828840 return shouldSuppress ?: false ;
829841}
830842
831- + (void )setNotificationOpenedHandler : (OSNotificationOpenedBlock)block {
832- _notificationOpenedHandler = block;
833- [OneSignalLog onesignalLog: ONE_S_LL_VERBOSE message: @" Notification opened handler set successfully" ];
834- [self fireNotificationOpenedHandlerForUnprocessedEvents ];
835-
843+ + (void )addClickListener : (NSObject <OSNotificationClickListener>*)listener {
844+ [self .clickListeners addObject: listener];
845+ [OneSignalLog onesignalLog: ONE_S_LL_VERBOSE message: @" Notification click listener added successfully" ];
846+ [self fireClickListenersForUnprocessedEvents ];
847+ }
848+
849+ + (void )removeClickListener : (NSObject <OSNotificationClickListener>*)listener {
850+ [self .clickListeners removeObject: listener];
851+ [OneSignalLog onesignalLog: ONE_S_LL_VERBOSE message: @" Notification click listener removed successfully" ];
836852}
837853
838854+ (void )addForegroundLifecycleListener : (NSObject <OSNotificationLifecycleListener> *_Nullable)listener {
@@ -845,24 +861,24 @@ + (void)removeForegroundLifecycleListener:(NSObject<OSNotificationLifecycleListe
845861 [OneSignalLog onesignalLog: ONE_S_LL_VERBOSE message: @" ForegroundLifecycleListener removed successfully" ];
846862}
847863
848- + (NSMutableArray <OSNotificationOpenedResult *>*)getUnprocessedOpenedNotifis {
849- if (!_unprocessedOpenedNotifis )
850- _unprocessedOpenedNotifis = [NSMutableArray new ];
851- return _unprocessedOpenedNotifis ;
864+ + (NSMutableArray <OSNotificationClickEvent *>*)getUnprocessedClickEvents {
865+ if (!_unprocessedClickEvents )
866+ _unprocessedClickEvents = [NSMutableArray new ];
867+ return _unprocessedClickEvents ;
852868}
853869
854- + (void )addUnprocessedOpenedNotifi : (OSNotificationOpenedResult*) result {
855- [[self getUnprocessedOpenedNotifis ] addObject: result ];
870+ + (void )addUnprocessedClickEvent : (OSNotificationClickEvent*) event {
871+ [[self getUnprocessedClickEvents ] addObject: event ];
856872}
857873
858- + (void )fireNotificationOpenedHandlerForUnprocessedEvents {
859- if (!_notificationOpenedHandler)
874+ + (void )fireClickListenersForUnprocessedEvents {
875+ if (self. clickListeners . count == 0 ) {
860876 return ;
861-
862- for (OSNotificationOpenedResult* notification in [self getUnprocessedOpenedNotifis ]) {
863- _notificationOpenedHandler (notification);
864877 }
865- _unprocessedOpenedNotifis = [NSMutableArray new ];
878+ for (OSNotificationClickEvent* event in [self getUnprocessedClickEvents ]) {
879+ [self fireClickListenersForEvent: event];
880+ }
881+ _unprocessedClickEvents = [NSMutableArray new ];
866882}
867883
868884+ (BOOL )receiveRemoteNotification : (UIApplication*)application UserInfo : (NSDictionary *)userInfo completionHandler : (void (^)(UIBackgroundFetchResult))completionHandler {
0 commit comments