@@ -816,13 +816,22 @@ + (void)sendPurchases:(NSArray*)purchases {
816816// - 2A. iOS 9 - Notification received while app is in focus.
817817// - 2B. iOS 10 - Notification received/displayed while app is in focus.
818818+ (void )notificationOpened : (NSDictionary *)messageDict isActive : (BOOL )isActive {
819- // Should be called first, other methods relay on this global state below.
820- [OneSignalHelper lastMessageReceived: messageDict];
821-
822819 NSDictionary * customDict = [messageDict objectForKey: @" os_data" ];
823820 if (!customDict)
824821 customDict = [messageDict objectForKey: @" custom" ];
825822
823+ // Prevent duplicate calls
824+ static NSString * lastMessageID = @" " ;
825+ if (customDict && customDict[@" i" ]) {
826+ NSString * currentNotificationId = customDict[@" i" ];
827+ if ([currentNotificationId isEqualToString: lastMessageID])
828+ return ;
829+ lastMessageID = customDict[@" i" ];
830+ }
831+
832+ // Should be called first, other methods relay on this global state below.
833+ [OneSignalHelper lastMessageReceived: messageDict];
834+
826835 BOOL inAppAlert = false ;
827836 if (isActive) {
828837 if (![[NSUserDefaults standardUserDefaults ] objectForKey: @" ONESIGNAL_ALERT_OPTION" ]) {
@@ -869,7 +878,6 @@ + (void)notificationOpened:(NSDictionary*)messageDict isActive:(BOOL)isActive {
869878 [OneSignal submitNotificationOpened: messageId];
870879 }
871880 else {
872-
873881 // app was in background / not running and opened due to a tap on a notification or an action check what type
874882 NSString * actionSelected = NULL ;
875883 OSNotificationActionType type = OSNotificationActionTypeOpened;
@@ -1047,8 +1055,7 @@ + (void) remoteSilentNotification:(UIApplication*)application UserInfo:(NSDictio
10471055 if (userInfo[@" os_data" ][@" buttons" ] || userInfo[@" at" ] || userInfo[@" o" ])
10481056 data = userInfo;
10491057
1050- // If buttons -> Data is buttons
1051- // Otherwise if titles or body or attachment -> data is everything
1058+ // Genergate local notification for action button and/or attachments.
10521059 if (data) {
10531060 if (NSClassFromString (@" UNUserNotificationCenter" )) {
10541061 #if XC8_AVAILABLE
@@ -1060,20 +1067,22 @@ + (void) remoteSilentNotification:(UIApplication*)application UserInfo:(NSDictio
10601067 [[UIApplication sharedApplication ] scheduleLocalNotification: notification];
10611068 }
10621069 }
1063- // Method was called due to a tap on a notification
1070+ // Method was called due to a tap on a notification - Fire open notification
10641071 else if (application.applicationState != UIApplicationStateBackground) {
10651072 [OneSignalHelper lastMessageReceived: userInfo];
1066- [OneSignalHelper handleNotificationReceived: OSNotificationDisplayTypeNotification];
1073+ if (application.applicationState == UIApplicationStateActive)
1074+ [OneSignalHelper handleNotificationReceived: OSNotificationDisplayTypeNotification];
10671075 [OneSignal notificationOpened: userInfo isActive: NO ];
10681076 return ;
10691077 }
1070-
1071- /* Handle the notification reception */
1072- [OneSignalHelper lastMessageReceived: userInfo];
1073- if ([OneSignalHelper isRemoteSilentNotification: userInfo])
1074- [OneSignalHelper handleNotificationReceived: OSNotificationDisplayTypeNone];
1075- else
1076- [OneSignalHelper handleNotificationReceived: OSNotificationDisplayTypeNotification];
1078+ // content-available notification received in the background - Fire handleNotificationReceived block in app
1079+ else {
1080+ [OneSignalHelper lastMessageReceived: userInfo];
1081+ if ([OneSignalHelper isRemoteSilentNotification: userInfo])
1082+ [OneSignalHelper handleNotificationReceived: OSNotificationDisplayTypeNone];
1083+ else
1084+ [OneSignalHelper handleNotificationReceived: OSNotificationDisplayTypeNotification];
1085+ }
10771086}
10781087
10791088// iOS 8-9 - Entry point when OneSignal action button notifiation is displayed or opened.
@@ -1125,10 +1134,14 @@ + (void)syncHashedEmail:(NSString *)email {
11251134@end
11261135
11271136// Swizzles UIApplication class to swizzling the other following classes:
1128- // - UIApplication - setDelegate: - Used to swizzle all UIApplicationDelegate selectors on the passed in class.
1129- // - Normally this the AppDelegate class but since UIApplicationDelegate is a "interface" this could be any class.
1130- // - UNUserNotificationCenter - setDelegate: - For iOS 10 only, swizzle all UNUserNotificationCenterDelegate selectors on the passed in class.
1131- // - This may or may not be set so we set our own now in registerAsUNNotificationCenterDelegate to an empty class.
1137+ // - UIApplication
1138+ // - setDelegate:
1139+ // - Used to swizzle all UIApplicationDelegate selectors on the passed in class.
1140+ // - Almost always this is the AppDelegate class but since UIApplicationDelegate is an "interface" this could be any class.
1141+ // - UNUserNotificationCenter
1142+ // - setDelegate:
1143+ // - For iOS 10 only, swizzle all UNUserNotificationCenterDelegate selectors on the passed in class.
1144+ // - This may or may not be set so we set our own now in registerAsUNNotificationCenterDelegate to an empty class.
11321145//
11331146// Note1: Do NOT move this category to it's own file. This is requried so when the app developer calls OneSignal.initWithLaunchOptions this load+
11341147// will fire along with it. This is due to how iOS loads .m files into memory instead of classes.
0 commit comments