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

Commit 0639640

Browse files
authored
Feature/itbl 2396 in app consume (#34)
* adding in consume logic * Working version of consume logic * Removing the campaignId from the InApp API calls.
1 parent b02a082 commit 0639640

File tree

6 files changed

+52
-39
lines changed

6 files changed

+52
-39
lines changed

Iterable-iOS-SDK/IterableAPI.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,22 +468,29 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
468468
@abstract Tracks a InAppOpen event with custom completion blocks
469469
470470
@param campaignId The campaignId of the notification
471-
@param templateId The templateId of the notification
472471
@param messageId The messageId of the notification
473472
*/
474-
- (void)trackInAppOpen:(NSNumber *)campaignId templateId:(NSNumber *)templateId messageId:(NSString *)messageId;
473+
- (void)trackInAppOpen:(NSString *)messageId;
475474

476475
/**
477476
@method
478477
479-
@abstract Tracks a inAppClick event with custom completion blocks
478+
@abstract Tracks a inAppClick event
480479
481-
@param campaignId The campaignId of the notification
482-
@param templateId The templateId of the notification
483480
@param messageId The messageId of the notification
484481
@param buttonIndex The index of the button that was clicked
485482
*/
486-
- (void)trackInAppClick:(NSNumber *)campaignId templateId:(NSNumber *)templateId messageId:(NSString *)messageId buttonIndex:(NSNumber *)buttonIndex;
483+
- (void)trackInAppClick:(NSString *)messageId buttonIndex:(NSNumber *)buttonIndex;
484+
485+
/**
486+
@method
487+
488+
@abstract Consumes the notification and removes it from the list of inAppMessages
489+
490+
@param messageId The messageId of the notification
491+
*/
492+
- (void)inAppConsume:(NSString *)messageId;
493+
487494

488495
/*!
489496
@method

Iterable-iOS-SDK/IterableAPI.m

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -440,21 +440,17 @@ - (instancetype)initWithApiKey:(NSString *)apiKey andUserId:(NSString *)userId l
440440
}
441441

442442
// documented in IterableAPI.h
443-
- (void)trackInAppOpen:(NSNumber*)campaignId templateId:(NSNumber*)templateId messageId:(NSString *)messageId {
443+
- (void)trackInAppOpen:(NSString *)messageId {
444444
NSDictionary *args;
445445

446446
if (_email != nil) {
447447
args = @{
448448
ITBL_KEY_EMAIL: self.email,
449-
ITBL_KEY_CAMPAIGN_ID: campaignId,
450-
ITBL_KEY_TEMPLATE_ID: templateId,
451449
ITBL_KEY_MESSAGE_ID: messageId
452450
};
453451
} else {
454452
args = @{
455453
ITBL_KEY_USER_ID: self.userId,
456-
ITBL_KEY_CAMPAIGN_ID: campaignId,
457-
ITBL_KEY_TEMPLATE_ID: templateId,
458454
ITBL_KEY_MESSAGE_ID: messageId
459455
};
460456
}
@@ -463,21 +459,36 @@ - (void)trackInAppOpen:(NSNumber*)campaignId templateId:(NSNumber*)templateId me
463459
}
464460

465461
// documented in IterableAPI.h
466-
- (void)trackInAppClick:(NSNumber*)campaignId templateId:(NSNumber*)templateId messageId:(NSString *)messageId buttonIndex:(NSNumber*)buttonIndex {
462+
- (void)inAppConsume:(NSString *)messageId {
463+
NSDictionary *args;
464+
465+
if (_email != nil) {
466+
args = @{
467+
ITBL_KEY_EMAIL: self.email,
468+
ITBL_KEY_MESSAGE_ID: messageId
469+
};
470+
} else {
471+
args = @{
472+
ITBL_KEY_USER_ID: self.userId,
473+
ITBL_KEY_MESSAGE_ID: messageId
474+
};
475+
}
476+
NSURLRequest *request = [self createRequestForAction:ENDPOINT_INAPP_CONSUME withArgs:args];
477+
[self sendRequest:request onSuccess:[IterableAPI defaultOnSuccess:@"inAppConsume"] onFailure:[IterableAPI defaultOnFailure:@"inAppConsume"]];
478+
}
479+
480+
// documented in IterableAPI.h
481+
- (void)trackInAppClick:(NSString *)messageId buttonIndex:(NSNumber*)buttonIndex {
467482
NSDictionary *args;
468483
if (_email != nil) {
469484
args = @{
470485
ITBL_KEY_EMAIL: self.email,
471-
ITBL_KEY_CAMPAIGN_ID: campaignId,
472-
ITBL_KEY_TEMPLATE_ID: templateId,
473486
ITBL_KEY_MESSAGE_ID: messageId,
474487
ITERABLE_IN_APP_BUTTON_INDEX: buttonIndex
475488
};
476489
} else {
477490
args = @{
478491
ITBL_KEY_USER_ID: self.userId,
479-
ITBL_KEY_CAMPAIGN_ID: campaignId,
480-
ITBL_KEY_TEMPLATE_ID: templateId,
481492
ITBL_KEY_MESSAGE_ID: messageId,
482493
ITERABLE_IN_APP_BUTTON_INDEX: buttonIndex
483494
};
@@ -780,8 +791,9 @@ - (void)spawnInAppNotification:(ITEActionBlock)callbackBlock
780791
NSNumber *campaignId = [dialogOptions valueForKey:ITBL_KEY_CAMPAIGN_ID];
781792
NSString *messageId = [dialogOptions valueForKey:ITBL_KEY_MESSAGE_ID];
782793

783-
[self trackInAppOpen:campaignId templateId:templateId messageId:messageId];
784-
IterableNotificationMetadata *notification = [IterableNotificationMetadata metadataFromInAppOptions:campaignId templateId:templateId messageId:messageId];
794+
[self trackInAppOpen:messageId];
795+
[self inAppConsume:messageId];
796+
IterableNotificationMetadata *notification = [IterableNotificationMetadata metadataFromInAppOptions:messageId];
785797

786798
if (message != nil) {
787799
dispatch_sync(dispatch_get_main_queue(), ^{

Iterable-iOS-SDK/IterableConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extern NSString *const ITBL_DEVICE_USER_INTERFACE;
4747
#define ENDPOINT_COMMERCE_TRACK_PURCHASE @"commerce/trackPurchase"
4848
#define ENDPOINT_DISABLE_DEVICE @"users/disableDevice"
4949
#define ENDPOINT_GET_INAPP_MESSAGES @"inApp/getMessages"
50+
#define ENDPOINT_INAPP_CONSUME @"events/inAppConsume"
5051
#define ENDPOINT_PUSH_TARGET @"push/target"
5152
#define ENDPOINT_REGISTER_DEVICE_TOKEN @"users/registerDeviceToken"
5253
#define ENDPOINT_TRACK @"events/track"

Iterable-iOS-SDK/IterableInAppBaseViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ -(void)ITEActionButtonClicked:(UIButton *)sender {
3333

3434
if (_trackParams != nil) {
3535
NSNumber *buttonId = @(sender.tag);
36-
[api trackInAppClick:_trackParams.campaignId templateId:_trackParams.templateId messageId:_trackParams.messageId buttonIndex:buttonId];
36+
[api trackInAppClick:_trackParams.messageId buttonIndex:buttonId];
3737
}
3838

3939
if (customBlockCallback != nil && ![actionString isEqualToString:@""]) {

Iterable-iOS-SDK/IterableNotificationMetadata.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// IterableNotification.h
2+
// IterableNotificationMetadata.h
33
// Iterable-iOS-SDK
44
//
55
// Created by Ilya Brin on 6/7/16.
@@ -62,15 +62,13 @@ NS_ASSUME_NONNULL_BEGIN
6262
6363
@abstract Creates an `IterableNotificationMetadata` from a inApp notification
6464
65-
@param campaignId The notification campaignId
66-
@param templateId The notification templateId
6765
@param messageId The notification messageId
6866
6967
@return an instance of `IterableNotificationMetadata` with the specified properties; `nil` if this is not a valid InApp notification
7068
71-
@warning `metadataFromInAppOptions` will return `nil` if campaignId or templateId is nil
69+
@warning `metadataFromInAppOptions` will return `nil` if messageId is nil
7270
*/
73-
+ (nullable instancetype)metadataFromInAppOptions:(NSNumber *)campaignId templateId:(NSNumber *)templateId messageId:(NSString *)messageId;
71+
+ (nullable instancetype)metadataFromInAppOptions:(NSString *)messageId;
7472

7573
///////////////////////////
7674
/// @name Utility functions

Iterable-iOS-SDK/IterableNotificationMetadata.m

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// IterableNotification.m
2+
// IterableNotificationMetadata.m
33
// Iterable-iOS-SDK
44
//
55
// Created by Ilya Brin on 6/7/16.
@@ -77,19 +77,15 @@ - (instancetype)initFromLaunchOptions:(NSDictionary *)userInfo
7777
7878
@abstract Creates an `IterableNotificationMetadata` from a InApp payload
7979
80-
@param campaignId The notification campaignId
81-
@param templateId The notification templateId
8280
@param messageId The notification messageId
8381
8482
@return An instance of `IterableNotificationMetadata` with the specified properties
8583
8684
@warning This method assumes that `userInfo` is an Iterable notification (via `isIterableNotification` check beforehand)
8785
*/
88-
- (instancetype)initFromInAppOptions:(NSNumber *)campaignId templateId:(NSNumber *)templateId messageId:(NSString *)messageId
86+
- (instancetype)initFromInAppOptions:(NSString *)messageId
8987
{
9088
if (self = [super init]) {
91-
_campaignId = campaignId;
92-
_templateId = templateId;
9389
_messageId = messageId;
9490
}
9591
return self;
@@ -99,7 +95,7 @@ - (instancetype)initFromInAppOptions:(NSNumber *)campaignId templateId:(NSNumber
9995
/// @name Implementation
10096
////////////////////////
10197

102-
// documented in IterableNotification.h
98+
// documented in IterableNotificationMetadata.h
10399
+ (instancetype)metadataFromLaunchOptions:(NSDictionary *)userInfo
104100
{
105101
if ([IterableNotificationMetadata isIterableNotification:userInfo]) {
@@ -109,28 +105,27 @@ + (instancetype)metadataFromLaunchOptions:(NSDictionary *)userInfo
109105
}
110106
}
111107

112-
// documented in IterableNotification.h
113-
+ (instancetype)metadataFromInAppOptions:(NSNumber *)campaignId templateId:(NSNumber *)templateId messageId:(NSString *)messageId
108+
// documented in IterableNotificationMetadata.h
109+
+ (instancetype)metadataFromInAppOptions:(NSString *)messageId
114110
{
115-
if (campaignId != nil && templateId != nil) {
116-
return [[IterableNotificationMetadata alloc] initFromInAppOptions:campaignId templateId:templateId messageId:messageId];
111+
if (messageId != nil) {
112+
return [[IterableNotificationMetadata alloc] initFromInAppOptions:messageId];
117113
} else {
118114
return nil;
119115
}
120-
121116
}
122117

123-
// documented in IterableNotification.h
118+
// documented in IterableNotificationMetadata.h
124119
- (BOOL)isProof {
125120
return _campaignId.integerValue == 0 && _templateId.integerValue != 0;
126121
}
127122

128-
// documented in IterableNotification.h
123+
// documented in IterableNotificationMetadata.h
129124
- (BOOL)isTestPush {
130125
return _campaignId.integerValue == 0 && _templateId.integerValue == 0;
131126
}
132127

133-
// documented in IterableNotification.h
128+
// documented in IterableNotificationMetadata.h
134129
- (BOOL)isRealCampaignNotification {
135130
return !(_isGhostPush || [self isProof] || [self isTestPush]);
136131
}

0 commit comments

Comments
 (0)