@@ -872,24 +872,25 @@ + (void)sendPurchases:(NSArray*)purchases {
872872// - 2A. iOS 9 - Notification received while app is in focus.
873873// - 2B. iOS 10 - Notification received/displayed while app is in focus.
874874+ (void )notificationOpened : (NSDictionary *)messageDict isActive : (BOOL )isActive {
875+ onesignal_Log (ONE_S_LL_VERBOSE, @" notificationOpened:isActive called!" );
876+
875877 NSDictionary * customDict = [messageDict objectForKey: @" os_data" ];
876878 if (!customDict)
877879 customDict = [messageDict objectForKey: @" custom" ];
878880
879- // Prevent duplicate calls
880- static NSString * lastMessageID = @" " ;
881- if (customDict && customDict[@" i" ]) {
882- NSString * currentNotificationId = customDict[@" i" ];
883- if ([currentNotificationId isEqualToString: lastMessageID])
884- return ;
885- lastMessageID = customDict[@" i" ];
886- }
887-
888881 // Should be called first, other methods relay on this global state below.
889882 [OneSignalHelper lastMessageReceived: messageDict];
890883
891884 BOOL inAppAlert = false ;
892885 if (isActive) {
886+ // Prevent duplicate calls
887+ static NSString * lastAppActiveMessageId = @" " ;
888+ NSString * newId = [self checkForProcessedDups: customDict lastMessageId: lastAppActiveMessageId];
889+ if ([@" dup" isEqualToString: newId])
890+ return ;
891+ if (newId)
892+ lastAppActiveMessageId = newId;
893+
893894 if (![[NSUserDefaults standardUserDefaults ] objectForKey: @" ONESIGNAL_ALERT_OPTION" ]) {
894895 [[NSUserDefaults standardUserDefaults ] setObject: @(OSNotificationDisplayTypeInAppAlert) forKey: @" ONESIGNAL_ALERT_OPTION" ];
895896 [[NSUserDefaults standardUserDefaults ] synchronize ];
@@ -934,10 +935,18 @@ + (void)notificationOpened:(NSDictionary*)messageDict isActive:(BOOL)isActive {
934935 [OneSignal submitNotificationOpened: messageId];
935936 }
936937 else {
938+ // Prevent duplicate calls
939+ static NSString * lastnonActiveMessageId = @" " ;
940+ NSString * newId = [self checkForProcessedDups: customDict lastMessageId: lastnonActiveMessageId];
941+ if ([@" dup" isEqualToString: newId])
942+ return ;
943+ if (newId)
944+ lastnonActiveMessageId = newId;
945+
937946 // app was in background / not running and opened due to a tap on a notification or an action check what type
938947 NSString * actionSelected = NULL ;
939948 OSNotificationActionType type = OSNotificationActionTypeOpened;
940- if (messageDict[@" custom" ][@" a" ][@" actionSelected" ]) {
949+ if (messageDict[@" custom" ][@" a" ][@" actionSelected" ]) {
941950 actionSelected = messageDict[@" custom" ][@" a" ][@" actionSelected" ];
942951 type = OSNotificationActionTypeActionTaken;
943952 }
@@ -950,9 +959,19 @@ + (void)notificationOpened:(NSDictionary*)messageDict isActive:(BOOL)isActive {
950959 [OneSignalHelper handleNotificationAction: type actionID: actionSelected displayType: OSNotificationDisplayTypeNotification];
951960 [OneSignal handleNotificationOpened: messageDict isActive: isActive actionType: type displayType: OSNotificationDisplayTypeNotification];
952961 }
953-
954962}
955-
963+
964+ + (NSString *) checkForProcessedDups : (NSDictionary *)customDict lastMessageId : (NSString *)lastMessageId {
965+ if (customDict && customDict[@" i" ]) {
966+ NSString * currentNotificationId = customDict[@" i" ];
967+ if ([currentNotificationId isEqualToString: lastMessageId])
968+ return @" dup" ;
969+ return customDict[@" i" ];
970+ }
971+ return nil ;
972+ }
973+
974+
956975+ (void ) handleNotificationOpened : (NSDictionary *)messageDict isActive : (BOOL )isActive actionType : (OSNotificationActionType)actionType displayType : (OSNotificationDisplayType)displayType {
957976
958977
@@ -1145,7 +1164,8 @@ + (void)processLocalActionBasedNotification:(UILocalNotification*) notification
11451164 [OneSignal notificationOpened: userInfo isActive: isActive];
11461165
11471166 // Notification Tapped or notification Action Tapped
1148- [self handleNotificationOpened: userInfo isActive: isActive actionType: OSNotificationActionTypeActionTaken displayType: OSNotificationDisplayTypeNotification];
1167+ if (!isActive)
1168+ [self handleNotificationOpened: userInfo isActive: isActive actionType: OSNotificationActionTypeActionTaken displayType: OSNotificationDisplayTypeNotification];
11491169 }
11501170
11511171}
0 commit comments