Skip to content

Commit

Permalink
Always remove the window when an IAM is dismissed
Browse files Browse the repository at this point in the history
Cherry pick #1276
  • Loading branch information
emawby committed Aug 9, 2023
1 parent 0291cfa commit 9641884
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ - (void)presentInAppPreviewMessage:(OSInAppMessageInternal *)message {
- (void)displayMessage:(OSInAppMessageInternal *)message {
// Check if the app disabled IAMs for this device before showing an IAM
if (_isInAppMessagingPaused && !message.isPreview) {
[self cleanUpInAppWindow];
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"In app messages will not show while paused"];
return;
}
Expand Down Expand Up @@ -737,7 +738,7 @@ - (void)messageViewControllerWasDismissed:(OSInAppMessageInternal *)message disp
[self persistInAppMessageForRedisplay:showingIAM];
}
// Reset the IAM viewController to prepare for next IAM if one exists
self.viewController = nil;
[self cleanUpInAppWindow];
// Reset time since last IAM
[self setAndPersistTimeSinceLastMessage];

Expand All @@ -749,6 +750,19 @@ - (void)messageViewControllerWasDismissed:(OSInAppMessageInternal *)message disp
}
}

- (void)cleanUpInAppWindow {
self.viewController = nil;
if (self.window) {
/*
Hide the top level IAM window
After the IAM window is hidden, iOS will automatically promote the main window
This also re-shows the keyboard automatically if it had focus in a text input
*/
self.window.hidden = true;
self.window = nil;
}
}

- (void)setAndPersistTimeSinceLastMessage {
NSDate *timeSinceLastMessage = [NSDate new];
[self.triggerController timeSinceLastMessage:timeSinceLastMessage];
Expand All @@ -768,21 +782,12 @@ - (void)evaluateMessageDisplayQueue {
[self displayMessage:self.messageDisplayQueue.firstObject];
return;
} else {
[self hideWindow];
[self cleanUpInAppWindow];
// Evaulate any IAMs (could be new IAM or added trigger conditions)
[self evaluateMessages];
}
}

/*
Hide the top level IAM window
After the IAM window is hidden, iOS will automatically promote the main window
This also re-shows the keyboard automatically if it had focus in a text input
*/
- (void)hideWindow {
self.window.hidden = true;
}

- (void)persistInAppMessageForRedisplay:(OSInAppMessageInternal *)message {
// If the IAM doesn't have the re display prop or is a preview IAM there is no need to save it
if (![message.displayStats isRedisplayEnabled] || message.isPreview) {
Expand Down

0 comments on commit 9641884

Please sign in to comment.