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

Commit e8ded60

Browse files
authored
[ITBL-5239] Make sure we handle the 'old' payload correctly (#57)
* Handle legacy payload with a deep link URL through the delegate * Remove old code from ITBNotificationServiceExtension * Remove IterableAction from IterableAppExtensions * Add a test for legacy payload * Add braces around if/else statements
1 parent b65e1cd commit e8ded60

File tree

7 files changed

+61
-20
lines changed

7 files changed

+61
-20
lines changed

Iterable-iOS-SDK.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
9284CA74206DCA6C00404B74 /* IterableAPIResponseTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9284CA73206DCA6C00404B74 /* IterableAPIResponseTests.m */; };
6565
929330902099449F00DAE180 /* IterableAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 9293308E2099449F00DAE180 /* IterableAction.h */; settings = {ATTRIBUTES = (Public, ); }; };
6666
929330912099449F00DAE180 /* IterableAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 9293308F2099449F00DAE180 /* IterableAction.m */; };
67-
92933092209944AA00DAE180 /* IterableAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 9293308E2099449F00DAE180 /* IterableAction.h */; settings = {ATTRIBUTES = (Public, ); }; };
68-
92933093209944AD00DAE180 /* IterableAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 9293308F2099449F00DAE180 /* IterableAction.m */; };
6967
92C6325C208FF7AA00A7C216 /* IterableAppIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 92C6325A208FF7AA00A7C216 /* IterableAppIntegration.h */; settings = {ATTRIBUTES = (Public, ); }; };
7068
92C6325D208FF7AA00A7C216 /* IterableAppIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C6325B208FF7AA00A7C216 /* IterableAppIntegration.m */; };
7169
92FB47C020995A0F00DA94DC /* IterableActionRunner.h in Headers */ = {isa = PBXBuildFile; fileRef = 92FB47BE20995A0F00DA94DC /* IterableActionRunner.h */; };
@@ -422,7 +420,6 @@
422420
isa = PBXHeadersBuildPhase;
423421
buildActionMask = 2147483647;
424422
files = (
425-
92933092209944AA00DAE180 /* IterableAction.h in Headers */,
426423
9267AA1F20992F9C006AF394 /* IterableAppExtensions.h in Headers */,
427424
9267AA2820992FF9006AF394 /* ITBNotificationServiceExtension.h in Headers */,
428425
);
@@ -773,7 +770,6 @@
773770
buildActionMask = 2147483647;
774771
files = (
775772
9267AA2920992FF9006AF394 /* ITBNotificationServiceExtension.m in Sources */,
776-
92933093209944AD00DAE180 /* IterableAction.m in Sources */,
777773
);
778774
runOnlyForDeploymentPostprocessing = 0;
779775
};

Iterable-iOS-SDK/IterableActionRunner.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ + (void)executeAction:(IterableAction *)action {
2424
}
2525

2626
+ (void)openURL:(NSURL *)url action:(IterableAction *)action {
27+
if (url == nil) {
28+
return;
29+
}
30+
2731
if ([[IterableAPI sharedInstance].urlDelegate handleIterableURL:url fromAction:action]) {
2832
return;
2933
}

Iterable-iOS-SDK/IterableAppIntegration.m

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ + (void)performDefaultNotificationAction:(NSDictionary *)userInfo api:(IterableA
4545
itbl = userInfo;
4646
}
4747
#endif
48-
IterableAction *action = [IterableAction actionFromDictionary:itbl[ITBL_PAYLOAD_DEFAULT_ACTION]];
48+
49+
IterableAction *action = nil;
4950
NSDictionary *dataFields = @{ ITBL_KEY_ACTION_IDENTIFIER: ITBL_VALUE_DEFAULT_PUSH_OPEN_ACTION_ID };
51+
if (itbl[ITBL_PAYLOAD_DEFAULT_ACTION] != nil) {
52+
action = [IterableAction actionFromDictionary:itbl[ITBL_PAYLOAD_DEFAULT_ACTION]];
53+
} else {
54+
action = [self legacyDefaultActionFromPayload:userInfo];
55+
}
5056

5157
// Track push open
5258
[api trackPushOpen:userInfo dataFields:dataFields];
@@ -72,7 +78,11 @@ + (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti
7278

7379
if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
7480
dataFields[ITBL_KEY_ACTION_IDENTIFIER] = ITBL_VALUE_DEFAULT_PUSH_OPEN_ACTION_ID;
75-
action = [IterableAction actionFromDictionary:itbl[ITBL_PAYLOAD_DEFAULT_ACTION]];
81+
if (itbl[ITBL_PAYLOAD_DEFAULT_ACTION] != nil) {
82+
action = [IterableAction actionFromDictionary:itbl[ITBL_PAYLOAD_DEFAULT_ACTION]];
83+
} else {
84+
action = [self legacyDefaultActionFromPayload:userInfo];
85+
}
7686
}
7787
else if ([response.actionIdentifier isEqualToString:UNNotificationDismissActionIdentifier]) {
7888
// We don't track dismiss actions yet
@@ -100,8 +110,17 @@ + (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti
100110
//Execute the action
101111
[IterableActionRunner executeAction:action];
102112

103-
if (completionHandler)
113+
if (completionHandler) {
104114
completionHandler();
115+
}
116+
}
117+
118+
+ (IterableAction *)legacyDefaultActionFromPayload:(NSDictionary *)userInfo {
119+
if (userInfo[ITBL_PAYLOAD_DEEP_LINK_URL] != nil) {
120+
return [IterableAction actionFromDictionary:@{@"type": IterableActionTypeOpenUrl, @"data": userInfo[ITBL_PAYLOAD_DEEP_LINK_URL]}];
121+
} else {
122+
return nil;
123+
}
105124
}
106125

107126
@end

Iterable-iOS-SDK/IterableConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ extern NSString *const ITBL_DEVICE_USER_INTERFACE;
8383
//Push Payload
8484
#define ITBL_PAYLOAD_METADATA @"itbl"
8585
#define ITBL_PAYLOAD_MESSAGE_ID @"messageId"
86+
#define ITBL_PAYLOAD_DEEP_LINK_URL @"url"
8687
#define ITBL_PAYLOAD_ATTACHMENT_URL @"attachment-url"
8788
#define ITBL_PAYLOAD_ACTION_BUTTONS @"actionButtons"
8889
#define ITBL_PAYLOAD_DEFAULT_ACTION @"defaultAction"

Iterable-iOS-SDKTests/IterableNotificationResponseTests.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,33 @@ - (void)testAppLaunchPushActionBeforeiOS10 {
295295
}
296296
}
297297

298+
- (void)testLegacyDeepLinkPayload {
299+
if (@available(iOS 10, *)) {
300+
id actionRunnerMock = OCMClassMock([IterableActionRunner class]);
301+
NSString *messageId = [[NSUUID UUID] UUIDString];
302+
303+
NSDictionary *userInfo = @{
304+
@"itbl": @{
305+
@"campaignId": @1234,
306+
@"templateId": @4321,
307+
@"isGhostPush": @NO,
308+
@"messageId": messageId
309+
},
310+
@"url": @"https://example.com"
311+
};
312+
313+
UNNotificationResponse *response = [self notificationResponseWithUserInfo:userInfo actionIdentifier:UNNotificationDefaultActionIdentifier];
314+
315+
[IterableAppIntegration userNotificationCenter:nil didReceiveNotificationResponse:response withCompletionHandler:nil];
316+
317+
OCMVerify([actionRunnerMock executeAction:[OCMArg checkWithBlock:^BOOL(IterableAction *action) {
318+
XCTAssertEqual(action.type, @"openUrl");
319+
XCTAssertEqual(action.data, @"https://example.com");
320+
return YES;
321+
}]]);
322+
323+
[actionRunnerMock stopMocking];
324+
}
325+
}
326+
298327
@end

IterableAppExtensions.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Pod::Spec.new do |s|
8585
# Not including the public_header_files will make all headers public.
8686
#
8787

88-
s.source_files = "IterableAppExtensions/*.{h,m}", "Iterable-iOS-SDK/IterableAction.{h,m}", "Iterable-iOS-SDK/IterableConstants.{h,m}"
88+
s.source_files = "IterableAppExtensions/*.{h,m}", "Iterable-iOS-SDK/IterableConstants.h"
8989
# s.exclude_files = "Classes/Exclude"
9090

9191
# s.public_header_files = "Classes/**/*.h"

IterableAppExtensions/ITBNotificationServiceExtension.m

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
#import "ITBNotificationServiceExtension.h"
3-
#import "IterableAction.h"
43
#import "IterableConstants.h"
54

65
NSString *const IterableButtonTypeDefault = @"default";
@@ -16,9 +15,6 @@ @interface ITBNotificationServiceExtension ()
1615

1716
@implementation ITBNotificationServiceExtension
1817

19-
volatile int displayElements;
20-
volatile int count;
21-
2218
UNNotificationCategory* messageCategory;
2319

2420
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
@@ -64,14 +60,10 @@ - (BOOL)loadAttachment:(NSDictionary *) itblDictionary {
6460

6561
}
6662
}
67-
count++;
68-
//NSLog(@"url: %@",currentUrl);
69-
if (count >= displayElements) {
70-
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
71-
self.contentHandler(self.bestAttemptContent);
72-
}];
73-
}
74-
63+
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
64+
self.contentHandler(self.bestAttemptContent);
65+
}];
66+
7567
}] resume];
7668

7769
return YES;

0 commit comments

Comments
 (0)