Skip to content

Commit 2bce297

Browse files
committed
Add tags to IAM
* Add OSInAppMessageTag class * Add send Tags when available * Add remove Tags when available * Add test for new functionality
1 parent 2d391d3 commit 2bce297

File tree

10 files changed

+259
-9
lines changed

10 files changed

+259
-9
lines changed

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
7A12EBD723060A6F005C4FA5 /* OneSignalSessionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A12EBD523060A6F005C4FA5 /* OneSignalSessionManager.m */; };
8282
7A12EBDA23060AEE005C4FA5 /* OSOutcomesUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A12EBD923060AEE005C4FA5 /* OSOutcomesUtils.m */; };
8383
7A12EBDD23060B37005C4FA5 /* OSIndirectNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A12EBDC23060B37005C4FA5 /* OSIndirectNotification.m */; };
84+
7A1F2D8F2406EFC5007799A9 /* OSInAppMessageTag.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A1F2D8E2406EFC5007799A9 /* OSInAppMessageTag.m */; };
8485
7A674F192360D813001F9ACD /* OSBaseFocusTimeProcessor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A674F182360D813001F9ACD /* OSBaseFocusTimeProcessor.h */; };
8586
7A674F1B2360D82E001F9ACD /* OSBaseFocusTimeProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A674F1A2360D82E001F9ACD /* OSBaseFocusTimeProcessor.m */; };
8687
7A674F1C2360D82E001F9ACD /* OSBaseFocusTimeProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A674F1A2360D82E001F9ACD /* OSBaseFocusTimeProcessor.m */; };
@@ -93,6 +94,8 @@
9394
7A880F2C23FB45FB0081F5E8 /* OSInAppMessageOutcome.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A880F2A23FB45FB0081F5E8 /* OSInAppMessageOutcome.m */; };
9495
7A880F2D23FB45FB0081F5E8 /* OSInAppMessageOutcome.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A880F2A23FB45FB0081F5E8 /* OSInAppMessageOutcome.m */; };
9596
7A9173A2231971E5007848FA /* OneSignalReceiveReceiptsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A9173A1231971E5007848FA /* OneSignalReceiveReceiptsController.m */; };
97+
7AA2848A2406FC6400C25D76 /* OSInAppMessageTag.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A1F2D8E2406EFC5007799A9 /* OSInAppMessageTag.m */; };
98+
7AA2848B2406FC6500C25D76 /* OSInAppMessageTag.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A1F2D8E2406EFC5007799A9 /* OSInAppMessageTag.m */; };
9699
7AD8DDE7234BD3BE00747A8A /* OneSignalUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AD8DDE6234BD3BE00747A8A /* OneSignalUserDefaults.m */; };
97100
7ADE379422E8B69C00263048 /* OneSignalOutcomeEventsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7ADE379322E8B69C00263048 /* OneSignalOutcomeEventsController.m */; };
98101
7ADE37AD22F2554400263048 /* OneSignalOutcomeEventsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7ADE379322E8B69C00263048 /* OneSignalOutcomeEventsController.m */; };
@@ -403,6 +406,8 @@
403406
7A12EBD923060AEE005C4FA5 /* OSOutcomesUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSOutcomesUtils.m; sourceTree = "<group>"; };
404407
7A12EBDB23060B37005C4FA5 /* OSIndirectNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSIndirectNotification.h; sourceTree = "<group>"; };
405408
7A12EBDC23060B37005C4FA5 /* OSIndirectNotification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSIndirectNotification.m; sourceTree = "<group>"; };
409+
7A1F2D8E2406EFC5007799A9 /* OSInAppMessageTag.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageTag.m; sourceTree = "<group>"; };
410+
7A1F2D902406EFDA007799A9 /* OSInAppMessageTag.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageTag.h; sourceTree = "<group>"; };
406411
7A674F182360D813001F9ACD /* OSBaseFocusTimeProcessor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSBaseFocusTimeProcessor.h; sourceTree = "<group>"; };
407412
7A674F1A2360D82E001F9ACD /* OSBaseFocusTimeProcessor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSBaseFocusTimeProcessor.m; sourceTree = "<group>"; };
408413
7A72EB0D23E252C200B4D50F /* OSInAppMessageDisplayStats.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageDisplayStats.m; sourceTree = "<group>"; };
@@ -951,6 +956,8 @@
951956
7A72EB0D23E252C200B4D50F /* OSInAppMessageDisplayStats.m */,
952957
7A880F2923FB45CE0081F5E8 /* OSInAppMessageOutcome.h */,
953958
7A880F2A23FB45FB0081F5E8 /* OSInAppMessageOutcome.m */,
959+
7A1F2D902406EFDA007799A9 /* OSInAppMessageTag.h */,
960+
7A1F2D8E2406EFC5007799A9 /* OSInAppMessageTag.m */,
954961
);
955962
name = Model;
956963
sourceTree = "<group>";
@@ -1228,6 +1235,7 @@
12281235
7AF76E91234252210085F926 /* OSSessionResult.m in Sources */,
12291236
91F58D831E7C80DA0017D24D /* OneSignalNotificationSettingsIOS8.m in Sources */,
12301237
CAAEA68721ED68A40049CF15 /* OneSignalNotificationCategoryController.m in Sources */,
1238+
7A1F2D8F2406EFC5007799A9 /* OSInAppMessageTag.m in Sources */,
12311239
9D1BD9602379E7C300A064F7 /* OSOutcomeEvent.m in Sources */,
12321240
7A72EB0E23E252C200B4D50F /* OSInAppMessageDisplayStats.m in Sources */,
12331241
9124121E1E73342200E41FD7 /* OneSignalJailbreakDetection.m in Sources */,
@@ -1299,6 +1307,7 @@
12991307
91F58D861E7C88250017D24D /* OneSignalNotificationSettingsIOS8.m in Sources */,
13001308
CAAEA68821ED68A40049CF15 /* OneSignalNotificationCategoryController.m in Sources */,
13011309
9124121F1E73342200E41FD7 /* OneSignalJailbreakDetection.m in Sources */,
1310+
7AA2848A2406FC6400C25D76 /* OSInAppMessageTag.m in Sources */,
13021311
CA08FC7A1FE99B13004C445F /* OneSignalRequest.m in Sources */,
13031312
7A72EB0F23E252C700B4D50F /* OSInAppMessageDisplayStats.m in Sources */,
13041313
912412481E73369700E41FD7 /* OneSignalHelper.m in Sources */,
@@ -1404,6 +1413,7 @@
14041413
CA42CAC320D99CB90001F2F2 /* ProvisionalAuthorizationTests.m in Sources */,
14051414
5B58E4F8237CE7B4009401E0 /* UIDeviceOverrider.m in Sources */,
14061415
CA8E19022193C6B0009DA223 /* InAppMessagingIntegrationTests.m in Sources */,
1416+
7AA2848B2406FC6500C25D76 /* OSInAppMessageTag.m in Sources */,
14071417
CAB4112B20852E4C005A70D1 /* DelayedInitializationParameters.m in Sources */,
14081418
7AECE59223674A9700537907 /* OSAttributedFocusTimeProcessor.m in Sources */,
14091419
912412341E73342200E41FD7 /* OneSignalTracker.m in Sources */,

iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#import <Foundation/Foundation.h>
2929
#import "OSInAppMessageOutcome.h"
30+
#import "OSInAppMessageTag.h"
3031
#import "OSJSONHandling.h"
3132
#import "OneSignal.h"
3233

@@ -51,6 +52,9 @@ typedef NS_ENUM(NSUInteger, OSInAppMessageActionUrlType) {
5152
// The outcome to send for this action
5253
@property (strong, nonatomic, nullable) NSArray<OSInAppMessageOutcome *> *outcomes;
5354

55+
// The tags to send for this action
56+
@property (strong, nonatomic, nullable) OSInAppMessageTag *tags;
57+
5458
// Determines where the URL is loaded, ie. app opens a webview
5559
@property (nonatomic) OSInAppMessageActionUrlType urlActionType;
5660

iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ + (instancetype)instanceWithJson:(NSDictionary *)json {
7171
action.closesMessage = true; // Default behavior
7272

7373
NSMutableArray *outcomes = [NSMutableArray new];
74-
74+
//TODO: when backend is ready check that key matches
7575
if ([json[@"outcomes"] isKindOfClass:[NSArray class]]) {
7676
NSArray *outcomesString = json[@"outcomes"];
7777

@@ -81,7 +81,17 @@ + (instancetype)instanceWithJson:(NSDictionary *)json {
8181
}
8282
action.outcomes = outcomes;
8383

84+
if (json[@"tags"]) {
85+
action.tags= [OSInAppMessageTag instanceWithJson:json[@"tags"]];
86+
} else {
87+
action.tags = nil;
88+
}
89+
8490
return action;
8591
}
8692

93+
- (NSString *)description {
94+
return [NSString stringWithFormat:@"OSInAppMessageAction outcome: %@ \ntag: %@", _outcomes, _tags];
95+
}
96+
8797
@end

iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
* THE SOFTWARE.
2626
*/
2727

28+
#ifndef OSInAppMessageOutcome_h
29+
#define OSInAppMessageOutcome_h
30+
2831
#import <Foundation/Foundation.h>
2932
#import "OSJSONHandling.h"
3033
#import "OneSignal.h"
@@ -36,3 +39,5 @@
3639
@property (nonatomic) BOOL unique;
3740

3841
@end
42+
43+
#endif /* OSInAppMessageOutcome_h */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2020 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#ifndef OSInAppMessageTag_h
29+
#define OSInAppMessageTag_h
30+
31+
#import <Foundation/Foundation.h>
32+
#import "OSJSONHandling.h"
33+
#import "OneSignal.h"
34+
35+
@interface OSInAppMessageTag : NSObject <OSJSONDecodable>
36+
37+
@property (strong, nonatomic, nullable) NSDictionary *tagsToAdd;
38+
@property (strong, nonatomic, nullable) NSArray *tagsToRemove;
39+
40+
@end
41+
42+
#endif /* OSInAppMessageTag_h */
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2020 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import "OSInAppMessageTag.h"
29+
30+
@implementation OSInAppMessageTag
31+
32+
+ (instancetype)instanceWithData:(NSData *)data {
33+
NSError *error;
34+
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
35+
36+
if (error || !json) {
37+
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"Unable to decode in-app message tag JSON: %@", error.description ?: @"No Data"]];
38+
return nil;
39+
}
40+
41+
return [self instanceWithJson:json];
42+
}
43+
44+
+ (instancetype)instanceWithJson:(NSDictionary *)json {
45+
OSInAppMessageTag *tag = [OSInAppMessageTag new];
46+
47+
//TODO: when backend is ready check that key matches
48+
if ([json[@"adds"] isKindOfClass:[NSDictionary class]]) {
49+
tag.tagsToAdd = json[@"adds"];
50+
} else {
51+
tag.tagsToAdd = nil;
52+
}
53+
//TODO: when backend is ready check that key matches
54+
if ([json[@"removes"] isKindOfClass:[NSArray class]]) {
55+
tag.tagsToRemove = json[@"removes"];
56+
} else {
57+
tag.tagsToRemove = nil;
58+
}
59+
60+
return tag;
61+
}
62+
63+
+ (instancetype _Nullable)instancePreviewFromPayload:(OSNotificationPayload * _Nonnull)payload {
64+
return nil;
65+
}
66+
67+
- (NSString *)description {
68+
return [NSString stringWithFormat:@"OSInAppMessageTag tagsToAdd: %@ \ntagsToRemove: %@", _tagsToAdd, _tagsToRemove];
69+
}
70+
71+
@end

iOS_SDK/OneSignalSDK/Source/OSMessagingController.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,16 @@ - (void)sendClickRESTCall:(OSInAppMessage *)message withAction:(OSInAppMessageAc
510510
}];
511511
}
512512

513+
- (void)sendTagCallWithAction:(OSInAppMessageAction *)action {
514+
if (action.tags) {
515+
OSInAppMessageTag *tag = action.tags;
516+
if (tag.tagsToAdd)
517+
[OneSignal sendTags:tag.tagsToAdd];
518+
if (tag.tagsToRemove)
519+
[OneSignal deleteTags:tag.tagsToRemove];
520+
}
521+
}
522+
513523
- (void)sendOutcomes:(NSArray<OSInAppMessageOutcome *>*)outcomes {
514524
for (OSInAppMessageOutcome *outcome in outcomes) {
515525
if (outcome.unique) {
@@ -533,7 +543,7 @@ - (void)messageViewDidSelectAction:(OSInAppMessage *)message withAction:(OSInApp
533543
self.actionClickBlock(action);
534544

535545
[self sendClickRESTCall:message withAction:action];
536-
546+
[self sendTagCallWithAction:action];
537547
[self sendOutcomes:action.outcomes];
538548
}
539549

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ + (void)deleteTagsWithJsonString:(NSString*)jsonString {
12571257
+ (void)deleteTags:(NSArray*)keys onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock {
12581258
NSMutableDictionary* tags = [[NSMutableDictionary alloc] init];
12591259

1260-
for(NSString* key in keys) {
1260+
for (NSString* key in keys) {
12611261
if (tagsToSend && tagsToSend[key]) {
12621262
if (![tagsToSend[key] isEqual:@""])
12631263
[tagsToSend removeObjectForKey:key];

iOS_SDK/OneSignalSDK/Source/Requests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ + (instancetype _Nonnull)unattributedWithOutcome:(OSOutcomeEvent * _Nonnull)outc
537537
params[DEVICE] = deviceType;
538538

539539
params[OUTCOME_ID] = outcome.name;
540-
540+
541541
if ([outcome.weight doubleValue] > 0)
542542
params[WEIGHT] = outcome.weight;
543543

0 commit comments

Comments
 (0)