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

Commit c5466dc

Browse files
authored
Followup fix: only consume in-app messages if they're shown (#66)
1 parent e56f894 commit c5466dc

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

Iterable-iOS-SDK/IterableAPI.m

+4-3
Original file line numberDiff line numberDiff line change
@@ -1188,13 +1188,14 @@ - (void)spawnInAppNotification:(ITEActionBlock)callbackBlock
11881188
IterableNotificationMetadata *notification = [IterableNotificationMetadata metadataFromInAppOptions:messageId];
11891189

11901190
dispatch_async(dispatch_get_main_queue(), ^{
1191-
[IterableInAppManager showIterableNotificationHTML:html trackParams:(IterableNotificationMetadata*)notification callbackBlock:(ITEActionBlock)callbackBlock backgroundAlpha:backgroundAlpha padding:edgeInsets];
1191+
if ([IterableInAppManager showIterableNotificationHTML:html trackParams:notification callbackBlock:callbackBlock backgroundAlpha:backgroundAlpha padding:edgeInsets]) {
1192+
[self inAppConsume:messageId];
1193+
}
11921194
});
11931195
} else {
11941196
LogWarning(@"No href tag found in the in-app html payload: %@", html);
1197+
[self inAppConsume:messageId];
11951198
}
1196-
1197-
[self inAppConsume:messageId];
11981199
}
11991200
} else {
12001201
LogDebug(@"No notifications found for inApp payload %@", payload);

Iterable-iOS-SDK/IterableInAppManager.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
@param callbackBlock The callback to send after a button on the notification is clicked
3434
@param backgroundAlpha The background alpha behind the notification
3535
@param padding The padding around the notification
36+
@return A boolean indicating whether the notification was shown
3637
*/
37-
+(void) showIterableNotificationHTML:(NSString *)htmlString trackParams:(IterableNotificationMetadata*)trackParams callbackBlock:(ITEActionBlock)callbackBlock backgroundAlpha:(double)backgroundAlpha padding:(UIEdgeInsets)padding;
38+
+(BOOL) showIterableNotificationHTML:(NSString *)htmlString trackParams:(IterableNotificationMetadata*)trackParams callbackBlock:(ITEActionBlock)callbackBlock backgroundAlpha:(double)backgroundAlpha padding:(UIEdgeInsets)padding;
3839

3940
/*!
4041
@method

Iterable-iOS-SDK/IterableInAppManager.m

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#import <UIKit/UIKit.h>
1111

1212
#import "IterableInAppManager.h"
13-
#import "IterableConstants.h"
14-
#import "IterableNotificationMetadata.h"
1513
#import "IterableInAppHTMLViewController.h"
1614
#import "IterableLogging.h"
1715

@@ -31,7 +29,7 @@ @implementation IterableInAppManager
3129
static NSString *const IN_APP_AUTO_EXPAND = @"AutoExpand";
3230

3331
// documented in IterableInAppManager.h
34-
+(void) showIterableNotificationHTML:(NSString*)htmlString trackParams:(IterableNotificationMetadata*)trackParams callbackBlock:(ITEActionBlock)callbackBlock backgroundAlpha:(double)backgroundAlpha padding:(UIEdgeInsets)padding{
32+
+(BOOL) showIterableNotificationHTML:(NSString*)htmlString trackParams:(IterableNotificationMetadata*)trackParams callbackBlock:(ITEActionBlock)callbackBlock backgroundAlpha:(double)backgroundAlpha padding:(UIEdgeInsets)padding{
3533
if (htmlString != NULL) {
3634
UIViewController *topViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
3735
if([topViewController isKindOfClass:[UIViewController class]])
@@ -44,7 +42,7 @@ +(void) showIterableNotificationHTML:(NSString*)htmlString trackParams:(Iterable
4442

4543
if ([topViewController isKindOfClass:[IterableInAppHTMLViewController class]]) {
4644
LogWarning(@"Skipping the in-app notification: another notification is already being displayed");
47-
return;
45+
return NO;
4846
}
4947

5048
IterableInAppHTMLViewController *baseNotification;
@@ -54,10 +52,13 @@ +(void) showIterableNotificationHTML:(NSString*)htmlString trackParams:(Iterable
5452
[baseNotification ITESetPadding:padding];
5553

5654
topViewController.definesPresentationContext = YES;
57-
baseNotification.view.backgroundColor = [UIColor colorWithWhite:0 alpha:backgroundAlpha];;
55+
baseNotification.view.backgroundColor = [UIColor colorWithWhite:0 alpha:backgroundAlpha];
5856
baseNotification.modalPresentationStyle = UIModalPresentationOverCurrentContext;
5957

6058
[topViewController presentViewController:baseNotification animated:NO completion:nil];
59+
return YES;
60+
} else {
61+
return NO;
6162
}
6263
}
6364

Iterable-iOS-SDKTests/IterableInAppNotificationTests.m

+7
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,11 @@ - (void)testNotificationPaddingDefault {
165165
XCTAssertEqual(notificationType, INAPP_CENTER);
166166
}
167167

168+
- (void)testDoNotShowMultipleTimes {
169+
BOOL shownFirstTime = [IterableInAppManager showIterableNotificationHTML:@"" trackParams:nil callbackBlock:nil backgroundAlpha:0.0 padding:UIEdgeInsetsZero];
170+
BOOL shownSecondTime = [IterableInAppManager showIterableNotificationHTML:@"" trackParams:nil callbackBlock:nil backgroundAlpha:0.0 padding:UIEdgeInsetsZero];
171+
XCTAssertTrue(shownFirstTime);
172+
XCTAssertFalse(shownSecondTime);
173+
}
174+
168175
@end

0 commit comments

Comments
 (0)