@@ -322,6 +322,7 @@ - (void)presentInAppPreviewMessage:(OSInAppMessageInternal *)message {
322322- (void )displayMessage : (OSInAppMessageInternal *)message {
323323 // Check if the app disabled IAMs for this device before showing an IAM
324324 if (_isInAppMessagingPaused && !message.isPreview ) {
325+ [self cleanUpInAppWindow ];
325326 [OneSignal onesignalLog: ONE_S_LL_VERBOSE message: @" In app messages will not show while paused" ];
326327 return ;
327328 }
@@ -605,7 +606,7 @@ - (void)messageViewControllerWasDismissed:(OSInAppMessageInternal *)message disp
605606 [self persistInAppMessageForRedisplay: showingIAM];
606607 }
607608 // Reset the IAM viewController to prepare for next IAM if one exists
608- self. viewController = nil ;
609+ [ self cleanUpInAppWindow ] ;
609610 // Reset time since last IAM
610611 [self setAndPersistTimeSinceLastMessage ];
611612
@@ -617,6 +618,19 @@ - (void)messageViewControllerWasDismissed:(OSInAppMessageInternal *)message disp
617618 }
618619}
619620
621+ - (void )cleanUpInAppWindow {
622+ self.viewController = nil ;
623+ if (self.window ) {
624+ /*
625+ Hide the top level IAM window
626+ After the IAM window is hidden, iOS will automatically promote the main window
627+ This also re-shows the keyboard automatically if it had focus in a text input
628+ */
629+ self.window .hidden = true ;
630+ self.window = nil ;
631+ }
632+ }
633+
620634- (void )setAndPersistTimeSinceLastMessage {
621635 NSDate *timeSinceLastMessage = [NSDate new ];
622636 [self .triggerController timeSinceLastMessage: timeSinceLastMessage];
@@ -636,21 +650,12 @@ - (void)evaluateMessageDisplayQueue {
636650 [self displayMessage: self .messageDisplayQueue.firstObject];
637651 return ;
638652 } else {
639- [self hideWindow ];
653+ [self cleanUpInAppWindow ];
640654 // Evaulate any IAMs (could be new IAM or added trigger conditions)
641655 [self evaluateMessages ];
642656 }
643657}
644658
645- /*
646- Hide the top level IAM window
647- After the IAM window is hidden, iOS will automatically promote the main window
648- This also re-shows the keyboard automatically if it had focus in a text input
649- */
650- - (void )hideWindow {
651- self.window .hidden = true ;
652- }
653-
654659- (void )persistInAppMessageForRedisplay : (OSInAppMessageInternal *)message {
655660 // If the IAM doesn't have the re display prop or is a preview IAM there is no need to save it
656661 if (![message.displayStats isRedisplayEnabled ] || message.isPreview ) {
@@ -861,7 +866,6 @@ - (void)webViewContentFinishedLoading:(OSInAppMessageInternal *)message {
861866 self.window .windowLevel = UIWindowLevelAlert;
862867 self.window .frame = [[UIScreen mainScreen ] bounds ];
863868 }
864-
865869 self.window .rootViewController = _viewController;
866870 self.window .backgroundColor = [UIColor clearColor ];
867871 self.window .opaque = true ;
0 commit comments