clevertap-react-native 1.0.3 → 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,12 @@ 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
+ }
121
+
100
122
  #pragma mark - Push Notifications
101
123
 
102
124
  RCT_EXPORT_METHOD(registerForPush) {
@@ -478,6 +500,36 @@ RCT_EXPORT_METHOD(setDebugLevel:(int)level) {
478
500
  return _profile;
479
501
  }
480
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
+ }
481
533
 
482
534
  #pragma mark - App Inbox
483
535
 
@@ -542,15 +594,33 @@ RCT_EXPORT_METHOD(deleteInboxMessageForId:(NSString*)messageId) {
542
594
  [[self cleverTapInstance] deleteInboxMessageForID:messageId];
543
595
  }
544
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
+
545
614
  RCT_EXPORT_METHOD(initializeInbox) {
546
615
  RCTLogInfo(@"[CleverTap Inbox Initialize]");
547
616
  [[self cleverTapInstance] initializeInboxWithCallback:^(BOOL success) {
548
617
  if (success) {
549
618
  RCTLogInfo(@"[Inbox initialized]");
550
- [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapInboxDidInitialize object:nil userInfo:nil];
619
+ NSMutableDictionary *body = [NSMutableDictionary new];
620
+ [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapInboxDidInitialize object:nil userInfo:body];
551
621
  [[self cleverTapInstance] registerInboxUpdatedBlock:^{
552
622
  RCTLogInfo(@"[Inbox updated]");
553
- [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapInboxMessagesDidUpdate object:nil userInfo:nil];
623
+ [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapInboxMessagesDidUpdate object:nil userInfo:body];
554
624
  }];
555
625
  }
556
626
  }];
@@ -643,13 +713,13 @@ RCT_EXPORT_METHOD(showInbox:(NSDictionary*)styleConfig) {
643
713
  - (void)messageDidSelect:(CleverTapInboxMessage *_Nonnull)message atIndex:(int)index withButtonIndex:(int)buttonIndex {
644
714
  NSMutableDictionary *body = [NSMutableDictionary new];
645
715
  if ([message json] != nil) {
646
- NSError *error;
647
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[message json]
648
- options:0
649
- error:&error];
650
- NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
651
- body[@"data"] = jsonString;
716
+ body[@"data"] = [NSMutableDictionary dictionaryWithDictionary:[message json]];
717
+ } else {
718
+ body[@"data"] = [NSMutableDictionary new];
652
719
  }
720
+ body[@"contentPageIndex"] = @(index);
721
+ body[@"buttonIndex"] = @(buttonIndex);
722
+
653
723
  [[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapInboxMessageTapped object:nil userInfo:body];
654
724
  }
655
725
 
@@ -877,5 +947,70 @@ RCT_EXPORT_METHOD(isPushPermissionGranted:(RCTResponseSenderBlock)callback){
877
947
  }
878
948
  }
879
949
 
880
- @end
950
+ #pragma mark - Product Experiences: Vars
951
+
952
+ RCT_EXPORT_METHOD(syncVariables) {
953
+ RCTLogInfo(@"[CleverTap syncVariables]");
954
+ [[self cleverTapInstance]syncVariables];
955
+ }
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;
881
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
@@ -58,7 +58,6 @@
58
58
  [[cleverTapInstance featureFlags] setDelegate:self];
59
59
  [[cleverTapInstance productConfig] setDelegate:self];
60
60
  [cleverTapInstance setPushPermissionDelegate:self];
61
- [cleverTapInstance setLibrary:@"React-Native"];
62
61
  }
63
62
 
64
63
 
@@ -103,7 +102,7 @@
103
102
  - (void)pushNotificationTappedWithCustomExtras:(NSDictionary *)customExtras {
104
103
  NSMutableDictionary *pushNotificationExtras = [NSMutableDictionary new];
105
104
  if (customExtras != nil) {
106
- pushNotificationExtras[@"customExtras"] = customExtras;
105
+ pushNotificationExtras = [NSMutableDictionary dictionaryWithDictionary:customExtras];
107
106
  }
108
107
  [self postNotificationWithName:kCleverTapPushNotificationClicked andBody:pushNotificationExtras];
109
108
  }
@@ -113,19 +112,15 @@
113
112
 
114
113
  - (void)inAppNotificationDismissedWithExtras:(NSDictionary *)extras andActionExtras:(NSDictionary *)actionExtras {
115
114
  NSMutableDictionary *body = [NSMutableDictionary new];
116
- if (extras != nil) {
117
- body[@"extras"] = extras;
118
- }
119
- if (actionExtras != nil) {
120
- body[@"actionExtras"] = actionExtras;
121
- }
115
+ body[@"extras"] = (extras != nil) ? extras : [NSMutableDictionary new];
116
+ body[@"actionExtras"] = (actionExtras != nil) ? actionExtras : [NSMutableDictionary new];
122
117
  [self postNotificationWithName:kCleverTapInAppNotificationDismissed andBody:body];
123
118
  }
124
119
 
125
120
  - (void)inAppNotificationButtonTappedWithCustomExtras:(NSDictionary *)customExtras {
126
121
  NSMutableDictionary *body = [NSMutableDictionary new];
127
122
  if (customExtras != nil) {
128
- body[@"customExtras"] = customExtras;
123
+ body = [NSMutableDictionary dictionaryWithDictionary:customExtras];
129
124
  }
130
125
  [self postNotificationWithName:kCleverTapInAppNotificationButtonTapped andBody:body];
131
126
  }
@@ -147,29 +142,33 @@
147
142
  #pragma mark - CleverTapFeatureFlagsDelegate
148
143
 
149
144
  - (void)ctFeatureFlagsUpdated {
150
- [self postNotificationWithName:kCleverTapFeatureFlagsDidUpdate andBody:nil];
145
+ NSMutableDictionary *body = [NSMutableDictionary new];
146
+ [self postNotificationWithName:kCleverTapFeatureFlagsDidUpdate andBody:body];
151
147
  }
152
148
 
153
149
 
154
150
  #pragma mark - CleverTapProductConfigDelegate
155
151
 
156
152
  - (void)ctProductConfigFetched {
157
- [self postNotificationWithName:kCleverTapProductConfigDidFetch andBody:nil];
153
+ NSMutableDictionary *body = [NSMutableDictionary new];
154
+ [self postNotificationWithName:kCleverTapProductConfigDidFetch andBody:body];
158
155
  }
159
156
 
160
157
  - (void)ctProductConfigActivated {
161
- [self postNotificationWithName:kCleverTapProductConfigDidActivate andBody:nil];
158
+ NSMutableDictionary *body = [NSMutableDictionary new];
159
+ [self postNotificationWithName:kCleverTapProductConfigDidActivate andBody:body];
162
160
  }
163
161
 
164
162
  - (void)ctProductConfigInitialized {
165
- [self postNotificationWithName:kCleverTapProductConfigDidInitialize andBody:nil];
163
+ NSMutableDictionary *body = [NSMutableDictionary new];
164
+ [self postNotificationWithName:kCleverTapProductConfigDidInitialize andBody:body];
166
165
  }
167
166
 
168
167
  #pragma mark - CleverTapPushPermissionDelegate
169
168
 
170
169
  - (void)onPushPermissionResponse:(BOOL)accepted {
171
170
  NSMutableDictionary *body = [NSMutableDictionary new];
172
- body[@"isPermissionGranted"] = [NSNumber numberWithBool:accepted];
171
+ body[@"accepted"] = [NSNumber numberWithBool:accepted];
173
172
  [self postNotificationWithName:kCleverTapPushPermissionResponseReceived andBody:body];
174
173
  }
175
174
 
@@ -179,7 +178,7 @@
179
178
  NSMutableDictionary *pushNotificationExtras = [NSMutableDictionary new];
180
179
  NSDictionary *customExtras = self.pendingPushNotificationExtras;
181
180
  if (customExtras != nil) {
182
- pushNotificationExtras[@"customExtras"] = customExtras;
181
+ pushNotificationExtras = [NSMutableDictionary dictionaryWithDictionary:customExtras];
183
182
  [self postNotificationWithName:kCleverTapPushNotificationClicked andBody:pushNotificationExtras];
184
183
  }
185
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clevertap-react-native",
3
- "version": "1.0.3",
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>