Skip to content

Commit e1aa421

Browse files
committed
Fixed handleNotificationAction firing issues
* handleNotificationAction was not firing on iOS 10 if OSNotificationDisplayTypeNotification was set and I notification is tapped on as soon as it is shown at the time of the screen. - Before it hides into he notification center. * Fixed iOS 9 issue where handleNotificationAction would fire when the app is in focus when a notification with action buttons is received before it is opened. * Restored web view transition animation.
1 parent 9f42321 commit e1aa421

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

iOS_SDK/OneSignal/OneSignal.m

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

iOS_SDK/OneSignalWebView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ -(void)showInApp {
110110
[mainWindow addSubview:[viewControllerForPresentation view]];
111111

112112
@try {
113-
[viewControllerForPresentation presentViewController:navController animated:NO completion:nil];
113+
[viewControllerForPresentation presentViewController:navController animated:YES completion:nil];
114114
}
115115
@catch(NSException* exception) { }
116116
}

0 commit comments

Comments
 (0)