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