Skip to content

Commit 6779d7b

Browse files
committed
Fixed issue with state carrying over from test to test
1 parent 85ead62 commit 6779d7b

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

iOS_SDK/OneSignal/OneSignal.m

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,13 @@ + (void)sendPurchases:(NSArray*)purchases {
946946
}
947947

948948

949+
static NSString *_lastAppActiveMessageId;
950+
+ (void)setLastAppActiveMessageId:(NSString*)value { _lastAppActiveMessageId = value; }
951+
952+
static NSString *_lastnonActiveMessageId;
953+
+ (void)setLastnonActiveMessageId:(NSString*)value { _lastnonActiveMessageId = value; }
954+
955+
949956
// Entry point for the following:
950957
// - 1. (iOS all) - Opening notifications
951958
// - 2. Notification received
@@ -967,12 +974,11 @@ + (void)notificationOpened:(NSDictionary*)messageDict isActive:(BOOL)isActive {
967974
BOOL inAppAlert = false;
968975
if (isActive) {
969976
// Prevent duplicate calls
970-
static NSString* lastAppActiveMessageId = @"";
971-
NSString* newId = [self checkForProcessedDups:customDict lastMessageId:lastAppActiveMessageId];
977+
NSString* newId = [self checkForProcessedDups:customDict lastMessageId:_lastAppActiveMessageId];
972978
if ([@"dup" isEqualToString:newId])
973979
return;
974980
if (newId)
975-
lastAppActiveMessageId = newId;
981+
_lastAppActiveMessageId = newId;
976982

977983
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"ONESIGNAL_ALERT_OPTION"]) {
978984
[[NSUserDefaults standardUserDefaults] setObject:@(OSNotificationDisplayTypeInAppAlert) forKey:@"ONESIGNAL_ALERT_OPTION"];
@@ -1019,12 +1025,11 @@ + (void)notificationOpened:(NSDictionary*)messageDict isActive:(BOOL)isActive {
10191025
}
10201026
else {
10211027
// Prevent duplicate calls
1022-
static NSString* lastnonActiveMessageId = @"";
1023-
NSString* newId = [self checkForProcessedDups:customDict lastMessageId:lastnonActiveMessageId];
1028+
NSString* newId = [self checkForProcessedDups:customDict lastMessageId:_lastnonActiveMessageId];
10241029
if ([@"dup" isEqualToString:newId])
10251030
return;
10261031
if (newId)
1027-
lastnonActiveMessageId = newId;
1032+
_lastnonActiveMessageId = newId;
10281033

10291034
//app was in background / not running and opened due to a tap on a notification or an action check what type
10301035
NSString* actionSelected = NULL;

iOS_SDK/OneSignal/OneSignalHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
+ (UILocalNotification*)prepareUILocalNotification:(NSDictionary*)data :(NSDictionary*)userInfo;
6161
+ (BOOL)verifyURL:(NSString *)urlString;
6262
+ (BOOL)isRemoteSilentNotification:(NSDictionary*)msg;
63+
@property (class) NSString *lastMessageIdFromAction;
6364

6465
// - Networking
6566
+ (NSNumber*)getNetType;

iOS_SDK/OneSignal/OneSignalHelper.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ + (void)handleNotificationReceived:(OSNotificationDisplayType)displayType {
472472
handleNotificationReceived(notification);
473473
}
474474

475+
static NSString *_lastMessageIdFromAction;
476+
+ (void)setLastMessageIdFromAction:(NSString*)value { _lastMessageIdFromAction = value; }
477+
475478
+ (void)handleNotificationAction:(OSNotificationActionType)actionType actionID:(NSString*)actionID displayType:(OSNotificationDisplayType)displayType {
476479
if (!handleNotificationAction || ![self isOneSignalPayload])
477480
return;
@@ -482,10 +485,9 @@ + (void)handleNotificationAction:(OSNotificationActionType)actionType actionID:(
482485
OSNotificationOpenedResult * result = [[OSNotificationOpenedResult alloc] initWithNotification:notification action:action];
483486

484487
// Prevent duplicate calls to same action
485-
static NSString* lastMessageID = @"";
486-
if ([payload.notificationID isEqualToString:lastMessageID])
488+
if ([payload.notificationID isEqualToString:_lastMessageIdFromAction])
487489
return;
488-
lastMessageID = payload.notificationID;
490+
_lastMessageIdFromAction = payload.notificationID;
489491

490492
handleNotificationAction(result);
491493
}

iOS_SDK/UnitTests/UnitTests.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ - (void)setUp {
314314
lastUrl = nil;
315315
lastHTTPRequset = nil;
316316

317+
[OneSignalHelper lastMessageReceived:nil];
318+
OneSignalHelper.lastMessageIdFromAction = nil;
319+
[OneSignal setValue:nil forKeyPath:@"lastAppActiveMessageId"];
320+
[OneSignal setValue:nil forKeyPath:@"lastnonActiveMessageId"];
321+
322+
317323
notifTypesOverride = 7;
318324
authorizationStatus = [NSNumber numberWithInteger:UNAuthorizationStatusAuthorized];
319325

0 commit comments

Comments
 (0)