Skip to content

Commit 1068348

Browse files
author
Rodrigo Gomez Palacio
committed
Remove IAM Caching
Motivation: we should not cache IAMs since it is incongruent with RYW consistency. Example: there is an IAM targeting users on version 1.0. The user upgrades to 2.0 & should no longer see the IAM targeting 1.0. The source of truth is the backend & we should only show IAMs as calculated by segment membership.
1 parent 10e877b commit 1068348

File tree

5 files changed

+1
-39
lines changed

5 files changed

+1
-39
lines changed

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSInAppMessageMigrationController.m

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ + (void)migrateToOSInAppMessageInternal {
7777
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSInAppMessage from version: %ld", sdkVersion]];
7878

7979
[NSKeyedUnarchiver setClass:[OSInAppMessageInternal class] forClassName:@"OSInAppMessage"];
80-
// Messages Array
81-
NSArray<OSInAppMessageInternal *> *messages = [OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_MESSAGES_ARRAY
82-
defaultValue:[NSArray<OSInAppMessageInternal *> new]];
83-
if (messages && messages.count) {
84-
[NSKeyedArchiver setClassName:@"OSInAppMessageInternal" forClass:[OSInAppMessageInternal class]];
85-
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:messages];
86-
} else {
87-
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:nil];
88-
}
8980

9081
// Redisplay Messages Dict
9182
NSMutableDictionary <NSString *, OSInAppMessageInternal *> *redisplayedInAppMessages = [[NSMutableDictionary alloc] initWithDictionary:[OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY defaultValue:[NSMutableDictionary new]]];

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ NS_ASSUME_NONNULL_BEGIN
5151
+ (void)start;
5252
+ (void)removeInstance;
5353
- (void)presentInAppMessage:(OSInAppMessageInternal *)message;
54-
- (void)updateInAppMessagesFromCache;
5554
- (void)getInAppMessagesFromServer:(NSString * _Nullable)subscriptionId;
5655
- (void)messageViewImpressionRequest:(OSInAppMessageInternal *)message;
5756
- (void)messageViewPageImpressionRequest:(OSInAppMessageInternal *)message withPageId:(NSString *)pageId;

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ - (instancetype)init {
206206
self.dateGenerator = ^ NSTimeInterval {
207207
return [[NSDate date] timeIntervalSince1970];
208208
};
209-
self.messages = [OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_MESSAGES_ARRAY
210-
defaultValue:[NSArray<OSInAppMessageInternal *> new]];
209+
self.messages = [NSArray<OSInAppMessageInternal *> new];
211210
[self initializeTriggerController];
212211
self.messageDisplayQueue = [NSMutableArray new];
213212
self.clickListeners = [NSMutableArray new];
@@ -241,17 +240,11 @@ - (void)initializeTriggerController {
241240
dateFromString:timeSinceLastMessage]];
242241
}
243242

244-
- (void)updateInAppMessagesFromCache {
245-
self.messages = [OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_MESSAGES_ARRAY defaultValue:[NSArray new]];
246-
[self evaluateMessages];
247-
}
248-
249243
- (void)getInAppMessagesFromServer:(NSString *)subscriptionId {
250244
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
251245
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"getInAppMessagesFromServer"];
252246

253247
if (!subscriptionId) {
254-
[self updateInAppMessagesFromCache];
255248
return;
256249
}
257250

@@ -314,7 +307,6 @@ - (void)attemptFetchWithRetries:(NSString *)subscriptionId
314307
NSDictionary* responseHeaders = errorInfo[@"headers"];
315308

316309
if (!statusCode) {
317-
[self updateInAppMessagesFromCache];
318310
return;
319311
}
320312

@@ -342,9 +334,6 @@ - (void)attemptFetchWithRetries:(NSString *)subscriptionId
342334
}
343335
} else if (code >= 500 && code <= 599) {
344336
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Server error, skipping retries"];
345-
[self updateInAppMessagesFromCache];
346-
} else {
347-
[self updateInAppMessagesFromCache];
348337
}
349338
}];
350339
}
@@ -389,23 +378,15 @@ - (void)fetchInAppMessagesWithoutToken:(NSString *)subscriptionId {
389378
[self updateInAppMessagesFromServer:messages];
390379
return;
391380
}
392-
[self updateInAppMessagesFromCache];
393381
});
394382
} onFailure:^(NSError *error) {
395383
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"getInAppMessagesFromServer failure: %@", error.localizedDescription]];
396-
[self updateInAppMessagesFromCache];
397384
}];
398385
}
399386

400387
- (void)updateInAppMessagesFromServer:(NSArray<OSInAppMessageInternal *> *)newMessages {
401388
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"updateInAppMessagesFromServer"];
402389
self.messages = newMessages;
403-
404-
// Cache if messages passed in are not null, this method is called from on_session for
405-
// new messages and cached when foregrounding app
406-
if (self.messages)
407-
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:self.messages];
408-
409390
self.calledLoadTags = NO;
410391
[self resetRedisplayMessagesBySession];
411392
[self evaluateMessages];
@@ -426,11 +407,6 @@ - (void)deleteInactiveMessage:(OSInAppMessageInternal *)message {
426407
NSMutableArray *newMessagesArray = [NSMutableArray arrayWithArray:self.messages];
427408
[newMessagesArray removeObject: message];
428409
self.messages = newMessagesArray;
429-
if (self.messages) {
430-
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:self.messages];
431-
} else {
432-
[OneSignalUserDefaults.initStandard removeValueForKey:OS_IAM_MESSAGES_ARRAY];
433-
}
434410
}
435411

436412
/*

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/OSInAppMessagingDefines.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ typedef NS_ENUM(NSUInteger, OSTriggerOperatorType) {
7373
#define OS_IAM_CLICKED_SET_KEY @"OS_IAM_CLICKED_SET"
7474
#define OS_IAM_IMPRESSIONED_SET_KEY @"OS_IAM_IMPRESSIONED_SET"
7575
#define OS_IAM_PAGE_IMPRESSIONED_SET_KEY @"OS_IAM_PAGE_IMPRESSIONED_SET"
76-
#define OS_IAM_MESSAGES_ARRAY @"OS_IAM_MESSAGES_ARRAY"
7776
#define OS_IAM_REDISPLAY_DICTIONARY @"OS_IAM_REDISPLAY_DICTIONARY"
7877
#define OS_IAM_TIME_SINCE_LAST_MESSAGE_KEY @"OS_IAM_TIME_SINCE_LAST_MESSAGE"
7978

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,6 @@ + (void)startNewSessionInternal {
417417
// [OneSignalLocation sendLocation];
418418
// [self executePendingLiveActivityUpdates];
419419
// [self receivedInAppMessageJson:results[@"push"][@"in_app_messages"]]; // go to controller
420-
421-
// on failure:
422-
// [OSMessagingController.sharedInstance updateInAppMessagesFromCache]; // go to controller
423420
}
424421

425422
+ (void)startInAppMessages {

0 commit comments

Comments
 (0)