Skip to content
This repository was archived by the owner on Jul 22, 2020. It is now read-only.

Commit c0a136f

Browse files
authored
Only show one in-app message at a time (#65)
1 parent 4adca46 commit c0a136f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Iterable-iOS-SDK/IterableInAppManager.m

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "IterableConstants.h"
1414
#import "IterableNotificationMetadata.h"
1515
#import "IterableInAppHTMLViewController.h"
16+
#import "IterableLogging.h"
1617

1718
@interface IterableInAppManager ()
1819

@@ -32,26 +33,31 @@ @implementation IterableInAppManager
3233
// documented in IterableInAppManager.h
3334
+(void) showIterableNotificationHTML:(NSString*)htmlString trackParams:(IterableNotificationMetadata*)trackParams callbackBlock:(ITEActionBlock)callbackBlock backgroundAlpha:(double)backgroundAlpha padding:(UIEdgeInsets)padding{
3435
if (htmlString != NULL) {
35-
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
36-
if([rootViewController isKindOfClass:[UIViewController class]])
36+
UIViewController *topViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
37+
if([topViewController isKindOfClass:[UIViewController class]])
3738
{
38-
while (rootViewController.presentedViewController != nil)
39+
while (topViewController.presentedViewController != nil)
3940
{
40-
rootViewController = rootViewController.presentedViewController;
41+
topViewController = topViewController.presentedViewController;
4142
}
4243
}
4344

45+
if ([topViewController isKindOfClass:[IterableInAppHTMLViewController class]]) {
46+
LogWarning(@"Skipping the in-app notification: another notification is already being displayed");
47+
return;
48+
}
49+
4450
IterableInAppHTMLViewController *baseNotification;
4551
baseNotification = [[IterableInAppHTMLViewController alloc] initWithData:htmlString];
4652
[baseNotification ITESetTrackParams:trackParams];
4753
[baseNotification ITESetCallback:callbackBlock];
4854
[baseNotification ITESetPadding:padding];
4955

50-
rootViewController.definesPresentationContext = YES;
56+
topViewController.definesPresentationContext = YES;
5157
baseNotification.view.backgroundColor = [UIColor colorWithWhite:0 alpha:backgroundAlpha];;
5258
baseNotification.modalPresentationStyle = UIModalPresentationOverCurrentContext;
5359

54-
[rootViewController presentViewController:baseNotification animated:NO completion:nil];
60+
[topViewController presentViewController:baseNotification animated:NO completion:nil];
5561
}
5662
}
5763

0 commit comments

Comments
 (0)