Skip to content

Commit 0699891

Browse files
Merge pull request #494 from CleverTap/7.4.0
SDK-5364: Encryption, Inapp Previews, Inapp Delays
2 parents 8009218 + c5b6936 commit 0699891

32 files changed

Lines changed: 1487 additions & 125 deletions

CleverTapSDK.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@
302302
4EB4C8BE2AAD91AC00B7F045 /* CTTriggerEvaluator.h in Headers */ = {isa = PBXBuildFile; fileRef = 4EB4C8BC2AAD91AC00B7F045 /* CTTriggerEvaluator.h */; };
303303
4EB4C8BF2AAD91AC00B7F045 /* CTTriggerEvaluator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EB4C8BD2AAD91AC00B7F045 /* CTTriggerEvaluator.m */; };
304304
4ECD88312ADC8A05003885CE /* CTSessionManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ECD88302ADC8A05003885CE /* CTSessionManagerTests.m */; };
305+
4EEA76612ECF066C00E2CF1B /* CTInAppDelayManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EEA765E2ECF066C00E2CF1B /* CTInAppDelayManager.m */; };
306+
4EEA76622ECF066C00E2CF1B /* CTInAppTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EEA76602ECF066C00E2CF1B /* CTInAppTimer.m */; };
307+
4EEA76632ECF066C00E2CF1B /* CTInAppTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4EEA765F2ECF066C00E2CF1B /* CTInAppTimer.h */; };
308+
4EEA76642ECF066C00E2CF1B /* CTInAppDelayManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4EEA765D2ECF066C00E2CF1B /* CTInAppDelayManager.h */; };
305309
4EED219B29AF6368006CEA19 /* CTVarCacheTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EED219A29AF6368006CEA19 /* CTVarCacheTest.m */; };
306310
4EF0D5452AD84BCA0044C48F /* CTSessionManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4EF0D5432AD84BCA0044C48F /* CTSessionManager.h */; };
307311
4EF0D5462AD84BCA0044C48F /* CTSessionManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4EF0D5432AD84BCA0044C48F /* CTSessionManager.h */; };
@@ -472,7 +476,6 @@
472476
6BFC61AC2DDB6A5A00022EFF /* CTContentFetchManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BFC61AA2DDB6A5A00022EFF /* CTContentFetchManager.m */; };
473477
6BFC61B02DDF3F2800022EFF /* CTContentFetchManagerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BFC61AF2DDF3F2800022EFF /* CTContentFetchManagerDelegate.h */; };
474478
6BFC61C92DE8534500022EFF /* CTContentFetchManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BFC61C82DE8534500022EFF /* CTContentFetchManagerTests.m */; };
475-
7C87D796B6B66FEA0125244A /* Pods_shared_CleverTapSDKTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E760A38DDF7A8054BC91F93 /* Pods_shared_CleverTapSDKTests.framework */; };
476479
D0047B0A2098D45B0019C6FD /* CTLocalDataStore.h in Headers */ = {isa = PBXBuildFile; fileRef = D0047B082098D45B0019C6FD /* CTLocalDataStore.h */; settings = {ATTRIBUTES = (Private, ); }; };
477480
D0047B0B2098D45B0019C6FD /* CTLocalDataStore.m in Sources */ = {isa = PBXBuildFile; fileRef = D0047B092098D45B0019C6FD /* CTLocalDataStore.m */; };
478481
D0047B0E2098E2F00019C6FD /* CTProfileBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = D0047B0C2098E2F00019C6FD /* CTProfileBuilder.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -890,6 +893,10 @@
890893
4EC2D084278AAD8000F4DE54 /* IdentityManagementTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IdentityManagementTests.m; sourceTree = "<group>"; };
891894
4ECD88302ADC8A05003885CE /* CTSessionManagerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTSessionManagerTests.m; sourceTree = "<group>"; };
892895
4EDCDE4D278AC4DF0065E699 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
896+
4EEA765D2ECF066C00E2CF1B /* CTInAppDelayManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTInAppDelayManager.h; sourceTree = "<group>"; };
897+
4EEA765E2ECF066C00E2CF1B /* CTInAppDelayManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTInAppDelayManager.m; sourceTree = "<group>"; };
898+
4EEA765F2ECF066C00E2CF1B /* CTInAppTimer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTInAppTimer.h; sourceTree = "<group>"; };
899+
4EEA76602ECF066C00E2CF1B /* CTInAppTimer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTInAppTimer.m; sourceTree = "<group>"; };
893900
4EED219A29AF6368006CEA19 /* CTVarCacheTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTVarCacheTest.m; sourceTree = "<group>"; };
894901
4EEF4A382ADD05B600F090EB /* CTSessionManager+Tests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CTSessionManager+Tests.h"; sourceTree = "<group>"; };
895902
4EF0D5432AD84BCA0044C48F /* CTSessionManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTSessionManager.h; sourceTree = "<group>"; };
@@ -1163,7 +1170,6 @@
11631170
files = (
11641171
D0B044D02769933D000ED628 /* SDWebImage.framework in Frameworks */,
11651172
D02AC2DC276044F70031C1BE /* CleverTapSDK.framework in Frameworks */,
1166-
C24BD6D3D4BD083C821728E7 /* Pods_shared_CleverTapSDKTests.framework in Frameworks */,
11671173
);
11681174
runOnlyForDeploymentPostprocessing = 0;
11691175
};
@@ -1221,6 +1227,10 @@
12211227
6A3EBD2F2AA0701D00CE97D4 /* Matchers */,
12221228
4808030F292EB50D00C06E2F /* CTLocalInApp.h */,
12231229
48080310292EB50D00C06E2F /* CTLocalInApp.m */,
1230+
4EEA765D2ECF066C00E2CF1B /* CTInAppDelayManager.h */,
1231+
4EEA765E2ECF066C00E2CF1B /* CTInAppDelayManager.m */,
1232+
4EEA765F2ECF066C00E2CF1B /* CTInAppTimer.h */,
1233+
4EEA76602ECF066C00E2CF1B /* CTInAppTimer.m */,
12241234
49F9E6BA2552E97000EF2E5C /* resources */,
12251235
071EB4AF217F6427008F0FAB /* CTDismissButton.h */,
12261236
071EB478217F6427008F0FAB /* CTDismissButton.m */,
@@ -1737,7 +1747,6 @@
17371747
isa = PBXGroup;
17381748
children = (
17391749
6B68DA2D2DEA1D3700761CFE /* ContentFetch */,
1740-
0B03FA342DD4C3F900545F66 /* Encryption */,
17411750
4847D1702CDA1788008DC327 /* EventDatabase */,
17421751
6B9E95AD2C285F2F0002D557 /* FileDownload */,
17431752
6A4427C32AA6513C0098866F /* InApps */,
@@ -2268,6 +2277,8 @@
22682277
487C71842D8AC11D0052986F /* CTAppFunctionBuilder-Internal.h in Headers */,
22692278
D06F052821E802D400D1B6BD /* CTInboxBaseMessageCell.h in Headers */,
22702279
07B94548219EA34300D4C542 /* CTUserMO.h in Headers */,
2280+
4EEA76632ECF066C00E2CF1B /* CTInAppTimer.h in Headers */,
2281+
4EEA76642ECF066C00E2CF1B /* CTInAppDelayManager.h in Headers */,
22712282
D0405B4622050C5200D64EC3 /* CTInboxUtils.h in Headers */,
22722283
4E25E3C6278887A70008C888 /* CTLegacyIdentityRepo.h in Headers */,
22732284
6BF5A5912ACC854800CDED20 /* CTInAppDisplayManager.h in Headers */,
@@ -2727,7 +2738,6 @@
27272738
4E87397B2C92223C00FDFDFD /* CTDomainFactoryTests.m in Sources */,
27282739
0B5564562C25946C00B87284 /* CTUserInfoMigratorTest.m in Sources */,
27292740
6B68DA252DE8B0F000761CFE /* CTContentFetchManagerMock.m in Sources */,
2730-
4E2CF1442AC56D8F00441E8B /* CTEncryptionManagerTests.m in Sources */,
27312741
32394C2729FA278C00956058 /* CTUriHelperTest.m in Sources */,
27322742
487854072BF4BC4E00565685 /* CTFileDownloaderTests.m in Sources */,
27332743
6A59D20D2A334B8500531F9D /* NSDictionaryExtensionsTest.m in Sources */,
@@ -2884,6 +2894,8 @@
28842894
4EB4C8BF2AAD91AC00B7F045 /* CTTriggerEvaluator.m in Sources */,
28852895
0701E9652372DE9C0034AAC2 /* CleverTapDisplayUnit.m in Sources */,
28862896
072F9E3E21B1368000BC6313 /* CTInboxIconMessageCell.m in Sources */,
2897+
4EEA76612ECF066C00E2CF1B /* CTInAppDelayManager.m in Sources */,
2898+
4EEA76622ECF066C00E2CF1B /* CTInAppTimer.m in Sources */,
28872899
071EB4D8217F6427008F0FAB /* CTHalfInterstitialImageViewController.m in Sources */,
28882900
0797133021A2F09A0011C9A3 /* CTSwipeView.m in Sources */,
28892901
4E8B81662AD2ADAE00714BB4 /* CTSwizzleManager.m in Sources */,

CleverTapSDK/CTConstants.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ extern NSString *CLTAP_PROFILE_IDENTITY_KEY;
179179
#define CLTAP_PREFS_INAPP_KEY_CS @"inapp_notifs_cs"
180180
#define CLTAP_PREFS_INAPP_KEY_SS @"inapp_notifs_ss"
181181

182+
#define CLTAP_PREFS_DELAYED_INAPP_KEY @"delayed_inapp_notifs"
183+
182184
#define CLTAP_PREFS_CS_INAPP_ACTIVE_ASSETS @"cs_inapp_active_assets"
183185
#define CLTAP_PREFS_CS_INAPP_INACTIVE_ASSETS @"cs_inapp_inactive_assets"
184186
#define CLTAP_PREFS_CS_INAPP_ASSETS_LAST_DELETED_TS @"cs_inapp_assets_last_deleted_timestamp"
@@ -211,6 +213,11 @@ extern NSString *CLTAP_PROFILE_IDENTITY_KEY;
211213

212214
// whenTriggers
213215
#define CLTAP_INAPP_TRIGGERS @"whenTriggers"
216+
// delayAfterTrigger
217+
#define CLTAP_DELAY_AFTER_TRIGGER @"delayAfterTrigger"
218+
#define CLTAP_MAX_DELAY_SECONDS 1200
219+
#define CLTAP_MIN_DELAY_SECONDS 1
220+
#define CLTAP_MAX_DELAYED_INAPPS 20 // worst case - we assume 1 in-app per minute, session length 20 mins
214221

215222
// whenLimits
216223
#define CLTAP_INAPP_FC_LIMITS @"frequencyLimits"

CleverTapSDK/CTLocalDataStore.m

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,41 @@ - (NSMutableDictionary *)decryptPIIDataIfEncrypted:(NSMutableDictionary *)profil
10191019

10201020
return updatedProfile;
10211021
}
1022+
else if (lastEncryptionLevel == CleverTapEncryptionHigh && self.config.cryptManager) {
1023+
// Always store the local profile data in decrypted values.
1024+
NSMutableDictionary *updatedProfile = [NSMutableDictionary new];
1025+
1026+
for (NSString *key in profile) {
1027+
@try {
1028+
// Validate the value before attempting to decrypt
1029+
id value = profile[key];
1030+
if (!value || ![value isKindOfClass:[NSString class]]) {
1031+
CleverTapLogDebug(self.config.logLevel, @"%@: Invalid value for key: %@, skipping decryption", self, key);
1032+
updatedProfile[key] = value ?: [NSNull null];
1033+
continue;
1034+
}
1035+
1036+
NSString *stringValue = [NSString stringWithFormat:@"%@", value];
1037+
NSString *decryptedString = [self.config.cryptManager decryptString:stringValue];
1038+
1039+
// Validate decryption result
1040+
if (!decryptedString) {
1041+
CleverTapLogDebug(self.config.logLevel, @"%@: Failed to decrypt data for key: %@", self, key);
1042+
// Return original value if decryption fails
1043+
updatedProfile[key] = stringValue;
1044+
} else {
1045+
updatedProfile[key] = decryptedString;
1046+
}
1047+
} @catch (NSException *e) {
1048+
CleverTapLogDebug(self.config.logLevel, @"%@: Exception during decryption for key %@: %@", self, key, e);
1049+
// Add original value to avoid data loss
1050+
updatedProfile[key] = profile[key];
1051+
}
1052+
1053+
}
1054+
1055+
return updatedProfile;
1056+
}
10221057

10231058
return profile;
10241059
}
@@ -1036,6 +1071,14 @@ - (NSMutableDictionary *)cryptValuesIfNeeded:(NSMutableDictionary *)profile {
10361071
}
10371072
return updatedProfile;
10381073
}
1074+
else if (self.config.encryptionLevel == CleverTapEncryptionHigh && self.config.cryptManager) {
1075+
NSMutableDictionary *updatedProfile = [NSMutableDictionary new];
1076+
for (NSString *key in profile) {
1077+
NSString *value = [NSString stringWithFormat:@"%@",profile[key]];
1078+
updatedProfile[key] = [self.config.cryptManager encryptString:value];
1079+
}
1080+
return updatedProfile;
1081+
}
10391082

10401083
return profile;
10411084
}

CleverTapSDK/CTPlistInfo.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,13 @@ - (void)setEncryption:(NSString *)encryptionLevel {
137137
_encryptionLevel = CleverTapEncryptionNone;
138138
} else if (encryptionLevel && [encryptionLevel isEqualToString:@"1"]) {
139139
_encryptionLevel = CleverTapEncryptionMedium;
140-
} else {
140+
}
141+
else if (encryptionLevel && [encryptionLevel isEqualToString:@"2"]) {
142+
_encryptionLevel = CleverTapEncryptionHigh;
143+
}
144+
else {
141145
_encryptionLevel = CleverTapEncryptionNone;
142-
CleverTapLogStaticInternal(@"Supported encryption levels are only 0 and 1. Setting it to 0 by default");
146+
CleverTapLogStaticInternal(@"Supported encryption levels are only 0, 1 and 2. Setting it to 0 by default");
143147
}
144148
}
145149

CleverTapSDK/CTRequest.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ - (NSMutableURLRequest *)createURLRequestWithAdditionalHeaders: (NSDictionary *_
4848
[request setValue:value forHTTPHeaderField:key];
4949
}];
5050
}
51-
if ([_httpMethod isEqualToString:@"POST"] && _params > 0) {
51+
if ([_httpMethod isEqualToString:@"POST"] && ![CTUtils isNullOrEmpty:_params]) {
5252
NSString *jsonBody = [CTUtils jsonObjectToString:_params];
53-
request.HTTPBody = [jsonBody dataUsingEncoding:NSUTF8StringEncoding];
54-
request.HTTPMethod = @"POST";
53+
if (![CTUtils isNullOrEmpty:jsonBody]) {
54+
request.HTTPBody = [jsonBody dataUsingEncoding:NSUTF8StringEncoding];
55+
}
5556
}
57+
request.HTTPMethod = _httpMethod;
5658
return request;
5759
}
5860

CleverTapSDK/CTRequestFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
+ (CTRequest * _Nonnull)contentRequestWithConfig:(CleverTapInstanceConfig * _Nonnull)config params:(id _Nullable)params url:(NSString * _Nonnull)url;
1818
+ (CTRequest * _Nonnull)syncVarsRequestWithConfig:(CleverTapInstanceConfig * _Nonnull)config params:(id _Nullable)params domain:(NSString * _Nonnull)domain;
1919
+ (CTRequest * _Nonnull)syncTemplatesRequestWithConfig:(CleverTapInstanceConfig * _Nonnull)config params:(id _Nullable)params domain:(NSString * _Nonnull)domain;
20-
20+
+ (CTRequest * _Nonnull)previewRequestWithConfig:(CleverTapInstanceConfig * _Nonnull)config url:(NSString * _Nonnull)url;
2121
@end
2222

2323

CleverTapSDK/CTRequestFactory.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ + (CTRequest * _Nonnull)syncTemplatesRequestWithConfig:(CleverTapInstanceConfig
4141
return [self _createPostRequestWithConfig:config params:params url:url];
4242
}
4343

44+
+ (CTRequest * _Nonnull)previewRequestWithConfig:(CleverTapInstanceConfig * _Nonnull)config url:(NSString * _Nonnull)url {
45+
return [self _createGetRequestWithConfig:config url:url];
46+
}
47+
4448
+ (CTRequest * _Nonnull)_createPostRequestWithConfig:(CleverTapInstanceConfig * _Nonnull)config params:(id _Nullable)params url:(NSString * _Nonnull)url {
4549
return [self _createPostRequestWithConfig:config params:params url:url additionalHeaders:nil];
4650
}
4751

52+
+ (CTRequest * _Nonnull)_createGetRequestWithConfig:(CleverTapInstanceConfig * _Nonnull)config url:(NSString * _Nonnull)url {
53+
return [[CTRequest alloc] initWithHttpMethod:@"GET" config:config params:nil url:url additionalHeaders:nil];
54+
}
55+
4856
+ (CTRequest * _Nonnull)_createPostRequestWithConfig:(CleverTapInstanceConfig * _Nonnull)config params:(id _Nullable)params url:(NSString * _Nonnull)url additionalHeaders:(NSDictionary * _Nullable)additionalHeaders {
4957
return [[CTRequest alloc] initWithHttpMethod:@"POST" config:config params:params url:url additionalHeaders:additionalHeaders];
5058
}

CleverTapSDK/CTUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
+ (NSString *)jsonObjectToString:(id)object;
1212
+ (NSString *)getKeyWithSuffix:(NSString *)suffix accountID:(NSString *)accountID;
1313
+ (void)runSyncMainQueue:(void (^)(void))block;
14+
+ (void)runAsyncMainQueue:(void (^)(void))block;
1415
+ (double)haversineDistance:(CLLocationCoordinate2D)coordinateA coordinateB:(CLLocationCoordinate2D)coordinateB;
1516
+ (NSNumber * _Nullable)numberFromString:(NSString * _Nullable)string;
1617
+ (NSNumber * _Nullable)numberFromString:(NSString * _Nullable)string withLocale:(NSLocale * _Nullable)locale;

CleverTapSDK/CTUtils.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ + (void)runSyncMainQueue:(void (^)(void))block {
9999
}
100100
}
101101

102+
+ (void)runAsyncMainQueue:(void (^)(void))block {
103+
dispatch_async(dispatch_get_main_queue(), block);
104+
}
105+
102106
+ (double)haversineDistance:(CLLocationCoordinate2D)coordinateA coordinateB:(CLLocationCoordinate2D)coordinateB {
103107
// The Earth radius ranges from a maximum of about 6378 km (equatorial)
104108
// to a minimum of about 6357 km (polar).

CleverTapSDK/CleverTap+InAppNotifications.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@
4242
*/
4343
- (void)clearInAppResources:(BOOL)expiredOnly;
4444

45+
/*!
46+
@method
47+
48+
@abstract
49+
Discards inApp notifications until 'resumeInAppNotifications' is called for current session.
50+
51+
Automatically resumes InApp notifications display on CleverTap shared instance creation. Pending inApp notifications are not displayed.
52+
53+
@param dismissInAppIfVisible when true, dismisses the currently visible InApp (if any) immediately.
54+
when false, allows the currently visible InApp to remain displayed.
55+
*/
56+
- (void)discardInAppNotifications:(BOOL)dismissInAppIfVisible;
57+
4558
#endif
4659

4760
@end

0 commit comments

Comments
 (0)