diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessage.m b/iOS_SDK/OneSignalSDK/Source/OSInAppMessage.m index 233960cf9..3494e9f0f 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessage.m +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessage.m @@ -126,11 +126,7 @@ + (instancetype)instanceWithJson:(NSDictionary * _Nonnull)json { } else return nil; - - //TODO: This will need to be changed when we add core data or database to iOS, see android implementation for reference - if (json[@"displayed_in_session"]) { - message.isDisplayedInSession = json[@"displayed_in_session"]; - } + return message; } @@ -163,14 +159,12 @@ -(NSDictionary *)jsonRepresentation { if ([_displayStats isRedisplayEnabled]) { json[@"redisplay"] = [_displayStats jsonRepresentation]; } - //TODO: This will need to be changed when we add core data or database to iOS, see android implementation for reference - json[@"displayed_in_session"] = @(_isDisplayedInSession); return json; } - (NSString *)description { - return [NSString stringWithFormat:@"OSInAppMessage: \nmessageId: %@ \ntriggers: %@ \ndisplayStats: %@", self.messageId, self.triggers, self.displayStats]; + return [NSString stringWithFormat:@"OSInAppMessage: \nmessageId: %@ \ntriggers: %@ \ndisplayed_in_session: %@ \ndisplayStats: %@", self.messageId, self.triggers, self.isDisplayedInSession ? @"YES" : @"NO", self.displayStats]; } - (BOOL)isEqual:(id)object { @@ -196,6 +190,8 @@ - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:_variants forKey:@"variants"]; [encoder encodeObject:_triggers forKey:@"triggers"]; [encoder encodeObject:_displayStats forKey:@"displayStats"]; + //TODO: This will need to be changed when we add core data or database to iOS, see android implementation for reference + [encoder encodeBool:_isDisplayedInSession forKey:@"displayed_in_session"]; } - (id)initWithCoder:(NSCoder *)decoder { @@ -204,6 +200,8 @@ - (id)initWithCoder:(NSCoder *)decoder { _variants = [decoder decodeObjectForKey:@"variants"]; _triggers = [decoder decodeObjectForKey:@"triggers"]; _displayStats = [decoder decodeObjectForKey:@"displayStats"]; + //TODO: This will need to be changed when we add core data or database to iOS, see android implementation for reference + _isDisplayedInSession = [decoder decodeBoolForKey:@"displayed_in_session"]; } return self; } diff --git a/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m b/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m index 5123a823e..cdda2cf6b 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m +++ b/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m @@ -150,10 +150,12 @@ - (instancetype)init { - (void)updateInAppMessagesFromCache { self.messages = [OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_MESSAGES_ARRAY defaultValue:[NSArray new]]; + [self evaluateMessages]; } - (void)updateInAppMessagesFromOnSession:(NSArray *)newMessages { + [OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"updateInAppMessagesFromOnSession"]; self.messages = newMessages; // Cache if messages passed in are not null, this method is called from on_session for @@ -167,6 +169,8 @@ - (void)updateInAppMessagesFromOnSession:(NSArray *)newMessage } - (void)resetRedisplayMessagesBySession { + [OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"resetRedisplayMessagesBySession with redisplayedInAppMessages: %@", [_redisplayedInAppMessages description]]]; + for (NSString *messageId in _redisplayedInAppMessages) { [_redisplayedInAppMessages objectForKey:messageId].isDisplayedInSession = false; } @@ -347,12 +351,13 @@ - (void)setDataForRedisplay:(OSInAppMessage *)message { if (messageDismissed && redisplayMessageSavedData) { NSLog(@"Redisplay IAM: %@", message.jsonRepresentation.description); - [OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"setDataForRedisplay with message: %@", message]]; message.displayStats.displayQuantity = redisplayMessageSavedData.displayStats.displayQuantity; message.displayStats.lastDisplayTime = redisplayMessageSavedData.displayStats.lastDisplayTime; // Message that don't have triggers should display only once per session BOOL triggerHasChanged = message.isTriggerChanged || (!redisplayMessageSavedData.isDisplayedInSession && [message.triggers count] == 0); + + [OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"setDataForRedisplay with message: %@ \ntriggerHasChanged: %@ \nno triggers: %@ \ndisplayed in session saved: %@", message, message.isTriggerChanged ? @"YES" : @"NO", [message.triggers count] == 0 ? @"YES" : @"NO", redisplayMessageSavedData.isDisplayedInSession ? @"YES" : @"NO"]]; // Check if conditions are correct for redisplay if (triggerHasChanged && [message.displayStats isDelayTimeSatisfied:self.dateGenerator()] && @@ -495,7 +500,12 @@ - (void)persistInAppMessageForRedisplay:(OSInAppMessage *)message { [_redisplayedInAppMessages setObject:message forKey:message.messageId]; [OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY withValue:_redisplayedInAppMessages]; - [OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"persistInAppMessageForRedisplay: %@ \nredisplayedInAppMessages: %@", [message description], [_redisplayedInAppMessages description]]]; + [OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"persistInAppMessageForRedisplay: %@ \nredisplayedInAppMessages: %@", [message description], _redisplayedInAppMessages]]; + + let standardUserDefaults = OneSignalUserDefaults.initStandard; + let redisplayedInAppMessages = [[NSMutableDictionary alloc] initWithDictionary:[standardUserDefaults getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY defaultValue:[NSMutableDictionary new]]]; + + [OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"persistInAppMessageForRedisplay saved redisplayedInAppMessages: %@", [redisplayedInAppMessages description]]]; } - (void)handlePromptActions:(NSArray *> *)promptActions {