Skip to content

Commit c2a9be3

Browse files
authored
Merge pull request #1294 from OneSignal/user_model/fix_in_app_display
[User model] Fix in app display
2 parents cc22dee + c34fc63 commit c2a9be3

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ - (void)presentInAppPreviewMessage:(OSInAppMessageInternal *)message {
448448
- (void)displayMessage:(OSInAppMessageInternal *)message {
449449
// Check if the app disabled IAMs for this device before showing an IAM
450450
if (_isInAppMessagingPaused && !message.isPreview) {
451+
[self cleanUpInAppWindow];
451452
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"In app messages will not show while paused"];
452453
return;
453454
}
@@ -749,6 +750,19 @@ - (void)messageViewControllerWasDismissed:(OSInAppMessageInternal *)message disp
749750
}
750751
}
751752

753+
- (void)cleanUpInAppWindow {
754+
self.viewController = nil;
755+
if (self.window) {
756+
/*
757+
Hide the top level IAM window
758+
After the IAM window is hidden, iOS will automatically promote the main window
759+
This also re-shows the keyboard automatically if it had focus in a text input
760+
*/
761+
self.window.hidden = true;
762+
self.window = nil;
763+
}
764+
}
765+
752766
- (void)setAndPersistTimeSinceLastMessage {
753767
NSDate *timeSinceLastMessage = [NSDate new];
754768
[self.triggerController timeSinceLastMessage:timeSinceLastMessage];
@@ -768,21 +782,12 @@ - (void)evaluateMessageDisplayQueue {
768782
[self displayMessage:self.messageDisplayQueue.firstObject];
769783
return;
770784
} else {
771-
[self hideWindow];
785+
[self cleanUpInAppWindow];
772786
// Evaulate any IAMs (could be new IAM or added trigger conditions)
773787
[self evaluateMessages];
774788
}
775789
}
776790

777-
/*
778-
Hide the top level IAM window
779-
After the IAM window is hidden, iOS will automatically promote the main window
780-
This also re-shows the keyboard automatically if it had focus in a text input
781-
*/
782-
- (void)hideWindow {
783-
self.window.hidden = true;
784-
}
785-
786791
- (void)persistInAppMessageForRedisplay:(OSInAppMessageInternal *)message {
787792
// If the IAM doesn't have the re display prop or is a preview IAM there is no need to save it
788793
if (![message.displayStats isRedisplayEnabled] || message.isPreview) {

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageViewController.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,15 @@ @interface OSInAppMessageViewController ()
9595

9696
@implementation OSInAppMessageViewController
9797

98+
OSInAppMessageInternal *_dismissingMessage = nil;
99+
98100
- (instancetype _Nonnull)initWithMessage:(OSInAppMessageInternal *)inAppMessage delegate:(id<OSInAppMessageViewControllerDelegate>)delegate {
99101
if (self = [super init]) {
100102
self.message = inAppMessage;
101103
self.delegate = delegate;
102104
self.useHeightMargin = YES;
103105
self.useWidthMargin = YES;
106+
_dismissingMessage = nil;
104107
}
105108

106109
return self;
@@ -490,6 +493,10 @@ - (void)dismissCurrentInAppMessage:(BOOL)up withVelocity:(double)velocity {
490493
[self.delegate messageViewControllerWasDismissed:self.message displayed:NO];
491494
return;
492495
}
496+
497+
if (_dismissingMessage == self.message) {
498+
return;
499+
}
493500

494501
[self.delegate messageViewControllerWillDismiss:self.message];
495502

@@ -521,7 +528,7 @@ - (void)dismissCurrentInAppMessage:(BOOL)up withVelocity:(double)velocity {
521528
animationOption = UIViewAnimationOptionCurveEaseIn;
522529
dismissAnimationDuration = MIN_DISMISSAL_ANIMATION_DURATION;
523530
}
524-
531+
_dismissingMessage = self.message;
525532
[UIView animateWithDuration:dismissAnimationDuration delay:0.0f options:animationOption animations:^{
526533
self.view.backgroundColor = [UIColor clearColor];
527534
self.view.alpha = 0.0f;

0 commit comments

Comments
 (0)