clevertap-react-native 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,11 +17,14 @@
17
17
  #import "CleverTapInstanceConfig.h"
18
18
  #import "CTLocalInApp.h"
19
19
  #import "Clevertap+PushPermission.h"
20
+ #import "CleverTap+CTVar.h"
21
+ #import "CTVar.h"
20
22
 
21
23
  static NSDateFormatter *dateFormatter;
22
24
 
23
25
  @interface CleverTapReact()
24
26
  @property CleverTap *cleverTapInstance;
27
+ @property(nonatomic, strong) NSMutableDictionary *allVariables;
25
28
  @end
26
29
 
27
30
  @implementation CleverTapReact
@@ -52,6 +55,10 @@ RCT_EXPORT_MODULE();
52
55
  kCleverTapPushNotificationClicked: kCleverTapPushNotificationClicked,
53
56
  kCleverTapPushPermissionResponseReceived: kCleverTapPushPermissionResponseReceived,
54
57
  kCleverTapInAppNotificationShowed: kCleverTapInAppNotificationShowed,
58
+ kCleverTapOnVariablesChanged:
59
+ kCleverTapOnVariablesChanged,
60
+ kCleverTapOnValueChanged:
61
+ kCleverTapOnValueChanged,
55
62
  kXPS: kXPS
56
63
  };
57
64
  }
@@ -63,6 +70,15 @@ RCT_EXPORT_MODULE();
63
70
 
64
71
  # pragma mark - Launch
65
72
 
73
+ - (instancetype)init
74
+ {
75
+ self = [super init];
76
+ if (self) {
77
+ self.allVariables = [NSMutableDictionary dictionary];
78
+ }
79
+ return self;
80
+ }
81
+
66
82
  - (CleverTap *)cleverTapInstance {
67
83
  if (_cleverTapInstance != nil) {
68
84
  return _cleverTapInstance;
@@ -97,6 +113,11 @@ RCT_EXPORT_METHOD(getInitialUrl:(RCTResponseSenderBlock)callback) {
97
113
  }
98
114
  }
99
115
 
116
+ RCT_EXPORT_METHOD(setLibrary:(NSString*)name andVersion:(int)version) {
117
+ RCTLogInfo(@"[CleverTap setLibrary:%@ andVersion:%d]", name, version);
118
+ [[self cleverTapInstance] setLibrary:name];
119
+ [[self cleverTapInstance] setCustomSdkVersion:name version:version];
120
+ }
100
121
 
101
122
  #pragma mark - Push Notifications
102
123
 
@@ -479,6 +500,36 @@ RCT_EXPORT_METHOD(setDebugLevel:(int)level) {
479
500
  return _profile;
480
501
  }
481
502
 
503
+ - (CTVar *)createVarForName:(NSString *)name andValue:(id)value {
504
+
505
+ if ([value isKindOfClass:[NSString class]]) {
506
+ return [[self cleverTapInstance]defineVar:name withString:value];
507
+ }
508
+ if ([value isKindOfClass:[NSDictionary class]]) {
509
+ return [[self cleverTapInstance]defineVar:name withDictionary:value];
510
+ }
511
+ if ([value isKindOfClass:[NSNumber class]]) {
512
+ if ([self isBoolNumber:value]) {
513
+ return [[self cleverTapInstance]defineVar:name withBool:value];
514
+ }
515
+ return [[self cleverTapInstance]defineVar:name withNumber:value];
516
+ }
517
+ return nil;
518
+ }
519
+
520
+ - (BOOL)isBoolNumber:(NSNumber *)number {
521
+ CFTypeID boolID = CFBooleanGetTypeID();
522
+ CFTypeID numID = CFGetTypeID(CFBridgingRetain(number));
523
+ return (numID == boolID);
524
+ }
525
+
526
+ - (NSMutableDictionary *)getVariableValues {
527
+ NSMutableDictionary *varValues = [NSMutableDictionary dictionary];
528
+ [self.allVariables enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, CTVar* _Nonnull var, BOOL * _Nonnull stop) {
529
+ varValues[key] = var.value;
530
+ }];
531
+ return varValues;
532
+ }
482
533
 
483
534
  #pragma mark - App Inbox
484
535
 
@@ -543,15 +594,33 @@ RCT_EXPORT_METHOD(deleteInboxMessageForId:(NSString*)messageId) {
543
594
  [[self cleverTapInstance] deleteInboxMessageForID:messageId];
544
595
  }
545
596
 
597
+ RCT_EXPORT_METHOD(markReadInboxMessagesForIDs:(NSArray*)messageIds) {
598
+ if (!messageIds) return;
599
+ RCTLogInfo(@"[CleverTap markReadInboxMessagesForIDs]");
600
+ [[self cleverTapInstance] markReadInboxMessagesForIDs:messageIds];
601
+ }
602
+
603
+ RCT_EXPORT_METHOD(deleteInboxMessagesForIDs:(NSArray*)messageIds) {
604
+ if (!messageIds) return;
605
+ RCTLogInfo(@"[CleverTap deleteInboxMessagesForIDs]");
606
+ [[self cleverTapInstance] deleteInboxMessagesForIDs:messageIds];
607
+ }
608
+
609
+ RCT_EXPORT_METHOD(dismissInbox) {
610
+ RCTLogInfo(@"[CleverTap dismissAppInbox]");
611
+ [[self cleverTapInstance] dismissAppInbox];
612
+ }
613
+
546
614
  RCT_EXPORT_METHOD(initializeInbox) {
547
615
  RCTLogInfo(@"[CleverTap Inbox Initialize]");
548
616
  [[self cleverTapInstance] initializeInboxWithCallback:^(BOOL success) {
549
617
  if (success) {
550
618
  RCTLogInfo(@"[Inbox initialized]");
551
- [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapInboxDidInitialize object:nil userInfo:nil];
619
+ NSMutableDictionary *body = [NSMutableDictionary new];
620
+ [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapInboxDidInitialize object:nil userInfo:body];
552
621
  [[self cleverTapInstance] registerInboxUpdatedBlock:^{
553
622
  RCTLogInfo(@"[Inbox updated]");
554
- [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapInboxMessagesDidUpdate object:nil userInfo:nil];
623
+ [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapInboxMessagesDidUpdate object:nil userInfo:body];
555
624
  }];
556
625
  }
557
626
  }];
@@ -644,13 +713,13 @@ RCT_EXPORT_METHOD(showInbox:(NSDictionary*)styleConfig) {
644
713
  - (void)messageDidSelect:(CleverTapInboxMessage *_Nonnull)message atIndex:(int)index withButtonIndex:(int)buttonIndex {
645
714
  NSMutableDictionary *body = [NSMutableDictionary new];
646
715
  if ([message json] != nil) {
647
- NSError *error;
648
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[message json]
649
- options:0
650
- error:&error];
651
- NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
652
- body[@"data"] = jsonString;
716
+ body[@"data"] = [NSMutableDictionary dictionaryWithDictionary:[message json]];
717
+ } else {
718
+ body[@"data"] = [NSMutableDictionary new];
653
719
  }
720
+ body[@"contentPageIndex"] = @(index);
721
+ body[@"buttonIndex"] = @(buttonIndex);
722
+
654
723
  [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapInboxMessageTapped object:nil userInfo:body];
655
724
  }
656
725
 
@@ -878,5 +947,70 @@ RCT_EXPORT_METHOD(isPushPermissionGranted:(RCTResponseSenderBlock)callback){
878
947
  }
879
948
  }
880
949
 
881
- @end
950
+ #pragma mark - Product Experiences: Vars
951
+
952
+ RCT_EXPORT_METHOD(syncVariables) {
953
+ RCTLogInfo(@"[CleverTap syncVariables]");
954
+ [[self cleverTapInstance]syncVariables];
955
+ }
882
956
 
957
+ RCT_EXPORT_METHOD(syncVariablesinProd:(BOOL)isProduction) {
958
+ RCTLogInfo(@"[CleverTap syncVariables:isProduction]");
959
+ [[self cleverTapInstance]syncVariables:isProduction];
960
+ }
961
+
962
+ RCT_EXPORT_METHOD(getVariable:(NSString * _Nonnull)name callback:(RCTResponseSenderBlock)callback) {
963
+ RCTLogInfo(@"[CleverTap getVariable:name]");
964
+ CTVar *var = self.allVariables[name];
965
+ [self returnResult:var.value withCallback:callback andError:nil];
966
+ }
967
+
968
+ RCT_EXPORT_METHOD(getVariables:(RCTResponseSenderBlock)callback) {
969
+ RCTLogInfo(@"[CleverTap getVariables]");
970
+
971
+ NSMutableDictionary *varValues = [self getVariableValues];
972
+ [self returnResult:varValues withCallback:callback andError:nil];
973
+ }
974
+
975
+ RCT_EXPORT_METHOD(fetchVariables:(RCTResponseSenderBlock)callback) {
976
+ RCTLogInfo(@"[CleverTap fetchVariables]");
977
+ [[self cleverTapInstance]fetchVariables:^(BOOL success) {
978
+ [self returnResult:@(success) withCallback:callback andError:nil];
979
+ }];
980
+ }
981
+
982
+ RCT_EXPORT_METHOD(defineVariables:(NSDictionary*)variables) {
983
+ RCTLogInfo(@"[CleverTap defineVariables]");
984
+
985
+ if (!variables) return;
986
+
987
+ [variables enumerateKeysAndObjectsUsingBlock:^(NSString* _Nonnull key, id _Nonnull value, BOOL * _Nonnull stop) {
988
+ CTVar *var = [self createVarForName:key andValue:value];
989
+
990
+ if (var) {
991
+ self.allVariables[key] = var;
992
+ }
993
+ }];
994
+ }
995
+
996
+ RCT_EXPORT_METHOD(onVariablesChanged) {
997
+ RCTLogInfo(@"[CleverTap onVariablesChanged]");
998
+ [[self cleverTapInstance]onVariablesChanged:^{
999
+ [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapOnVariablesChanged object:nil userInfo:[self getVariableValues]];
1000
+ }];
1001
+ }
1002
+
1003
+ RCT_EXPORT_METHOD(onValueChanged:(NSString*)name) {
1004
+ RCTLogInfo(@"[CleverTap onValueChanged]");
1005
+ CTVar *var = self.allVariables[name];
1006
+ if (var) {
1007
+ [var onValueChanged:^{
1008
+ NSDictionary *varResult = @{
1009
+ var.name: var.value
1010
+ };
1011
+ [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapOnValueChanged object:nil userInfo:varResult];
1012
+ }];
1013
+ }
1014
+ }
1015
+
1016
+ @end
@@ -8,11 +8,12 @@
8
8
  RCT_EXPORT_MODULE();
9
9
 
10
10
  - (NSArray<NSString *> *)supportedEvents {
11
- return @[kCleverTapProfileDidInitialize, kCleverTapProfileSync, kCleverTapInAppNotificationDismissed, kCleverTapInboxDidInitialize, kCleverTapInboxMessagesDidUpdate, kCleverTapInAppNotificationButtonTapped, kCleverTapInboxMessageButtonTapped, kCleverTapInboxMessageTapped, kCleverTapDisplayUnitsLoaded, kCleverTapFeatureFlagsDidUpdate, kCleverTapProductConfigDidFetch, kCleverTapProductConfigDidActivate, kCleverTapProductConfigDidInitialize, kCleverTapPushNotificationClicked, kCleverTapPushPermissionResponseReceived, kCleverTapInAppNotificationShowed];
11
+ return @[kCleverTapProfileDidInitialize, kCleverTapProfileSync, kCleverTapInAppNotificationDismissed, kCleverTapInboxDidInitialize, kCleverTapInboxMessagesDidUpdate, kCleverTapInAppNotificationButtonTapped, kCleverTapInboxMessageButtonTapped, kCleverTapInboxMessageTapped, kCleverTapDisplayUnitsLoaded, kCleverTapFeatureFlagsDidUpdate, kCleverTapProductConfigDidFetch, kCleverTapProductConfigDidActivate, kCleverTapProductConfigDidInitialize, kCleverTapPushNotificationClicked, kCleverTapPushPermissionResponseReceived, kCleverTapInAppNotificationShowed, kCleverTapOnVariablesChanged, kCleverTapOnValueChanged];
12
12
  }
13
13
 
14
14
 
15
15
  - (void)startObserving {
16
+
16
17
  [[NSNotificationCenter defaultCenter] addObserver:self
17
18
  selector:@selector(emitEventInternal:)
18
19
  name:kCleverTapProfileDidInitialize
@@ -88,6 +89,14 @@ RCT_EXPORT_MODULE();
88
89
  name:kCleverTapPushPermissionResponseReceived
89
90
  object:nil];
90
91
 
92
+ [[NSNotificationCenter defaultCenter] addObserver:self
93
+ selector:@selector(emitEventInternal:)
94
+ name:kCleverTapOnVariablesChanged
95
+ object:nil];
96
+ [[NSNotificationCenter defaultCenter] addObserver:self
97
+ selector:@selector(emitEventInternal:)
98
+ name:kCleverTapOnValueChanged
99
+ object:nil];
91
100
  }
92
101
 
93
102
  - (void)stopObserving {
@@ -98,5 +107,4 @@ RCT_EXPORT_MODULE();
98
107
  [self sendEventWithName:notification.name body:notification.userInfo];
99
108
  }
100
109
 
101
-
102
110
  @end
@@ -10,5 +10,6 @@
10
10
  - (void)setDelegates:(CleverTap *)cleverTapInstance;
11
11
 
12
12
  @property NSString *launchDeepLink;
13
+ @property(nonatomic, strong) NSDictionary *pendingPushNotificationExtras;
13
14
 
14
15
  @end
@@ -3,6 +3,9 @@
3
3
 
4
4
  #import <UIKit/UIKit.h>
5
5
  #import <React/RCTLog.h>
6
+ #import <React/RCTBridge.h>
7
+ #import <React/RCTEventDispatcher.h>
8
+ #import <React/RCTRootView.h>
6
9
 
7
10
  #import "CleverTap+Inbox.h"
8
11
  #import "CleverTapUTMDetail.h"
@@ -32,9 +35,15 @@
32
35
  return sharedInstance;
33
36
  }
34
37
 
38
+
35
39
  - (instancetype)init {
36
40
  self = [super init];
37
41
  if (self) {
42
+
43
+ [[NSNotificationCenter defaultCenter] addObserver:self
44
+ selector:@selector(handleContentDidAppearNotification:)
45
+ name:RCTContentDidAppearNotification
46
+ object:nil];
38
47
  CleverTap *clevertap = [CleverTap sharedInstance];
39
48
  [self setDelegates:clevertap];
40
49
  }
@@ -49,14 +58,17 @@
49
58
  [[cleverTapInstance featureFlags] setDelegate:self];
50
59
  [[cleverTapInstance productConfig] setDelegate:self];
51
60
  [cleverTapInstance setPushPermissionDelegate:self];
52
- [cleverTapInstance setLibrary:@"React-Native"];
53
61
  }
54
62
 
63
+
55
64
  - (void)applicationDidLaunchWithOptions:(NSDictionary *)options {
56
65
  NSDictionary *notification = [options valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
57
- if (notification && notification[@"wzrk_dl"]) {
58
- self.launchDeepLink = notification[@"wzrk_dl"];
59
- RCTLogInfo(@"CleverTapReact: setting launch deeplink: %@", self.launchDeepLink);
66
+ if (notification){
67
+ self.pendingPushNotificationExtras = notification;
68
+ if (notification[@"wzrk_dl"]) {
69
+ self.launchDeepLink = notification[@"wzrk_dl"];
70
+ RCTLogInfo(@"CleverTapReact: setting launch deeplink: %@", self.launchDeepLink);
71
+ }
60
72
  }
61
73
  }
62
74
 
@@ -90,7 +102,7 @@
90
102
  - (void)pushNotificationTappedWithCustomExtras:(NSDictionary *)customExtras {
91
103
  NSMutableDictionary *pushNotificationExtras = [NSMutableDictionary new];
92
104
  if (customExtras != nil) {
93
- pushNotificationExtras[@"customExtras"] = customExtras;
105
+ pushNotificationExtras = [NSMutableDictionary dictionaryWithDictionary:customExtras];
94
106
  }
95
107
  [self postNotificationWithName:kCleverTapPushNotificationClicked andBody:pushNotificationExtras];
96
108
  }
@@ -100,19 +112,15 @@
100
112
 
101
113
  - (void)inAppNotificationDismissedWithExtras:(NSDictionary *)extras andActionExtras:(NSDictionary *)actionExtras {
102
114
  NSMutableDictionary *body = [NSMutableDictionary new];
103
- if (extras != nil) {
104
- body[@"extras"] = extras;
105
- }
106
- if (actionExtras != nil) {
107
- body[@"actionExtras"] = actionExtras;
108
- }
115
+ body[@"extras"] = (extras != nil) ? extras : [NSMutableDictionary new];
116
+ body[@"actionExtras"] = (actionExtras != nil) ? actionExtras : [NSMutableDictionary new];
109
117
  [self postNotificationWithName:kCleverTapInAppNotificationDismissed andBody:body];
110
118
  }
111
119
 
112
120
  - (void)inAppNotificationButtonTappedWithCustomExtras:(NSDictionary *)customExtras {
113
121
  NSMutableDictionary *body = [NSMutableDictionary new];
114
122
  if (customExtras != nil) {
115
- body[@"customExtras"] = customExtras;
123
+ body = [NSMutableDictionary dictionaryWithDictionary:customExtras];
116
124
  }
117
125
  [self postNotificationWithName:kCleverTapInAppNotificationButtonTapped andBody:body];
118
126
  }
@@ -134,30 +142,45 @@
134
142
  #pragma mark - CleverTapFeatureFlagsDelegate
135
143
 
136
144
  - (void)ctFeatureFlagsUpdated {
137
- [self postNotificationWithName:kCleverTapFeatureFlagsDidUpdate andBody:nil];
145
+ NSMutableDictionary *body = [NSMutableDictionary new];
146
+ [self postNotificationWithName:kCleverTapFeatureFlagsDidUpdate andBody:body];
138
147
  }
139
148
 
140
149
 
141
150
  #pragma mark - CleverTapProductConfigDelegate
142
151
 
143
152
  - (void)ctProductConfigFetched {
144
- [self postNotificationWithName:kCleverTapProductConfigDidFetch andBody:nil];
153
+ NSMutableDictionary *body = [NSMutableDictionary new];
154
+ [self postNotificationWithName:kCleverTapProductConfigDidFetch andBody:body];
145
155
  }
146
156
 
147
157
  - (void)ctProductConfigActivated {
148
- [self postNotificationWithName:kCleverTapProductConfigDidActivate andBody:nil];
158
+ NSMutableDictionary *body = [NSMutableDictionary new];
159
+ [self postNotificationWithName:kCleverTapProductConfigDidActivate andBody:body];
149
160
  }
150
161
 
151
162
  - (void)ctProductConfigInitialized {
152
- [self postNotificationWithName:kCleverTapProductConfigDidInitialize andBody:nil];
163
+ NSMutableDictionary *body = [NSMutableDictionary new];
164
+ [self postNotificationWithName:kCleverTapProductConfigDidInitialize andBody:body];
153
165
  }
154
166
 
155
167
  #pragma mark - CleverTapPushPermissionDelegate
156
168
 
157
169
  - (void)onPushPermissionResponse:(BOOL)accepted {
158
170
  NSMutableDictionary *body = [NSMutableDictionary new];
159
- body[@"isPermissionGranted"] = [NSNumber numberWithBool:accepted];
171
+ body[@"accepted"] = [NSNumber numberWithBool:accepted];
160
172
  [self postNotificationWithName:kCleverTapPushPermissionResponseReceived andBody:body];
161
173
  }
162
174
 
175
+ - (void)handleContentDidAppearNotification:(NSNotification *)notification {
176
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
177
+
178
+ NSMutableDictionary *pushNotificationExtras = [NSMutableDictionary new];
179
+ NSDictionary *customExtras = self.pendingPushNotificationExtras;
180
+ if (customExtras != nil) {
181
+ pushNotificationExtras = [NSMutableDictionary dictionaryWithDictionary:customExtras];
182
+ [self postNotificationWithName:kCleverTapPushNotificationClicked andBody:pushNotificationExtras];
183
+ }
184
+ }
185
+
163
186
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clevertap-react-native",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "CleverTap React Native SDK.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Workspace
3
- version = "1.0">
4
- <FileRef
5
- location = "self:">
6
- </FileRef>
7
- </Workspace>
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>IDEDidComputeMac32BitWarning</key>
6
- <true/>
7
- </dict>
8
- </plist>
@@ -1,14 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>SchemeUserState</key>
6
- <dict>
7
- <key>CleverTapReact.xcscheme_^#shared#^_</key>
8
- <dict>
9
- <key>orderHint</key>
10
- <integer>0</integer>
11
- </dict>
12
- </dict>
13
- </dict>
14
- </plist>