diff --git a/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m b/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m index d90d0ed76..3cd706834 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m +++ b/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m @@ -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; } @@ -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]; @@ -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]; @@ -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) { @@ -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;