Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iam/remove iam caching #1499

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,6 @@ + (void)migrateToOSInAppMessageInternal {
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSInAppMessage from version: %ld", sdkVersion]];

[NSKeyedUnarchiver setClass:[OSInAppMessageInternal class] forClassName:@"OSInAppMessage"];
// Messages Array
NSArray<OSInAppMessageInternal *> *messages = [OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_MESSAGES_ARRAY
defaultValue:[NSArray<OSInAppMessageInternal *> new]];
if (messages && messages.count) {
[NSKeyedArchiver setClassName:@"OSInAppMessageInternal" forClass:[OSInAppMessageInternal class]];
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:messages];
} else {
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:nil];
}

// Redisplay Messages Dict
NSMutableDictionary <NSString *, OSInAppMessageInternal *> *redisplayedInAppMessages = [[NSMutableDictionary alloc] initWithDictionary:[OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY defaultValue:[NSMutableDictionary new]]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)start;
+ (void)removeInstance;
- (void)presentInAppMessage:(OSInAppMessageInternal *)message;
- (void)updateInAppMessagesFromCache;
- (void)getInAppMessagesFromServer:(NSString * _Nullable)subscriptionId;
- (void)messageViewImpressionRequest:(OSInAppMessageInternal *)message;
- (void)messageViewPageImpressionRequest:(OSInAppMessageInternal *)message withPageId:(NSString *)pageId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ - (instancetype)init {
self.dateGenerator = ^ NSTimeInterval {
return [[NSDate date] timeIntervalSince1970];
};
self.messages = [OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_MESSAGES_ARRAY
defaultValue:[NSArray<OSInAppMessageInternal *> new]];
self.messages = [NSArray<OSInAppMessageInternal *> new];
[self initializeTriggerController];
self.messageDisplayQueue = [NSMutableArray new];
self.clickListeners = [NSMutableArray new];
Expand Down Expand Up @@ -242,17 +241,11 @@ - (void)initializeTriggerController {
dateFromString:timeSinceLastMessage]];
}

- (void)updateInAppMessagesFromCache {
self.messages = [OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_MESSAGES_ARRAY defaultValue:[NSArray new]];
[self evaluateMessages];
}

- (void)getInAppMessagesFromServer:(NSString *)subscriptionId {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"getInAppMessagesFromServer"];

if (!subscriptionId) {
[self updateInAppMessagesFromCache];
return;
}

Expand Down Expand Up @@ -328,7 +321,6 @@ - (void)attemptFetchWithRetries:(NSString *)subscriptionId
NSDictionary* responseHeaders = errorInfo[@"headers"];

if (!statusCode) {
[self updateInAppMessagesFromCache];
return;
}

Expand Down Expand Up @@ -356,9 +348,6 @@ - (void)attemptFetchWithRetries:(NSString *)subscriptionId
}
} else if (code >= 500 && code <= 599) {
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Server error, skipping retries"];
[self updateInAppMessagesFromCache];
} else {
[self updateInAppMessagesFromCache];
}
}];
}
Expand Down Expand Up @@ -403,23 +392,15 @@ - (void)fetchInAppMessagesWithoutToken:(NSString *)subscriptionId {
[self updateInAppMessagesFromServer:messages];
return;
}
[self updateInAppMessagesFromCache];
});
} onFailure:^(NSError *error) {
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"getInAppMessagesFromServer failure: %@", error.localizedDescription]];
[self updateInAppMessagesFromCache];
}];
}

- (void)updateInAppMessagesFromServer:(NSArray<OSInAppMessageInternal *> *)newMessages {
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"updateInAppMessagesFromServer"];
self.messages = newMessages;

// Cache if messages passed in are not null, this method is called from on_session for
// new messages and cached when foregrounding app
if (self.messages)
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:self.messages];

self.calledLoadTags = NO;
[self resetRedisplayMessagesBySession];
[self evaluateMessages];
Expand All @@ -440,11 +421,6 @@ - (void)deleteInactiveMessage:(OSInAppMessageInternal *)message {
NSMutableArray *newMessagesArray = [NSMutableArray arrayWithArray:self.messages];
[newMessagesArray removeObject: message];
self.messages = newMessagesArray;
if (self.messages) {
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:self.messages];
} else {
[OneSignalUserDefaults.initStandard removeValueForKey:OS_IAM_MESSAGES_ARRAY];
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ typedef NS_ENUM(NSUInteger, OSTriggerOperatorType) {
#define OS_IAM_CLICKED_SET_KEY @"OS_IAM_CLICKED_SET"
#define OS_IAM_IMPRESSIONED_SET_KEY @"OS_IAM_IMPRESSIONED_SET"
#define OS_IAM_PAGE_IMPRESSIONED_SET_KEY @"OS_IAM_PAGE_IMPRESSIONED_SET"
#define OS_IAM_MESSAGES_ARRAY @"OS_IAM_MESSAGES_ARRAY"
#define OS_IAM_REDISPLAY_DICTIONARY @"OS_IAM_REDISPLAY_DICTIONARY"
#define OS_IAM_TIME_SINCE_LAST_MESSAGE_KEY @"OS_IAM_TIME_SINCE_LAST_MESSAGE"

Expand Down
3 changes: 0 additions & 3 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,6 @@ + (void)startNewSessionInternal {
// [OneSignalLocation sendLocation];
// [self executePendingLiveActivityUpdates];
// [self receivedInAppMessageJson:results[@"push"][@"in_app_messages"]]; // go to controller

// on failure:
// [OSMessagingController.sharedInstance updateInAppMessagesFromCache]; // go to controller
}

+ (void)startInAppMessages {
Expand Down
Loading