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

Always remove the window when an IAM is dismissed #1276

Merged
merged 1 commit into from
Jul 17, 2023
Merged
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
28 changes: 16 additions & 12 deletions iOS_SDK/OneSignalSDK/Source/OSMessagingController.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,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];
[OneSignal onesignalLog:ONE_S_LL_VERBOSE message:@"In app messages will not show while paused"];
return;
}
Expand Down Expand Up @@ -605,7 +606,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 @@ -617,6 +618,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 @@ -636,21 +650,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 Expand Up @@ -861,7 +866,6 @@ - (void)webViewContentFinishedLoading:(OSInAppMessageInternal *)message {
self.window.windowLevel = UIWindowLevelAlert;
self.window.frame = [[UIScreen mainScreen] bounds];
}

self.window.rootViewController = _viewController;
self.window.backgroundColor = [UIColor clearColor];
self.window.opaque = true;
Expand Down
Loading