From 3ebb17f6c2f47a6915154617e927ee72f4fa5fee Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Thu, 7 Nov 2024 13:39:57 +0530 Subject: [PATCH 1/3] chore(MC-2302): Update HTML template for inapp preview. - Added check for inapp advanced builder type also. --- CleverTapSDK/CTConstants.h | 1 + CleverTapSDK/InApps/CTInAppDisplayManager.m | 3 +- .../InApps/resources/image_interstitial.html | 30 ++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CleverTapSDK/CTConstants.h b/CleverTapSDK/CTConstants.h index c1f91ae1..4f6b5099 100644 --- a/CleverTapSDK/CTConstants.h +++ b/CleverTapSDK/CTConstants.h @@ -231,6 +231,7 @@ extern NSString *CLTAP_PROFILE_IDENTITY_KEY; #define CLTAP_INAPP_PREVIEW_TYPE @"wzrk_inapp_type" #define CLTAP_INAPP_IMAGE_INTERSTITIAL_TYPE @"image-interstitial" +#define CLTAP_INAPP_ADVANCED_BUILDER_TYPE @"advanced-builder" #define CLTAP_INAPP_IMAGE_INTERSTITIAL_CONFIG @"imageInterstitialConfig" #define CLTAP_INAPP_HTML_SPLIT @"\"##Vars##\"" #define CLTAP_INAPP_IMAGE_INTERSTITIAL_HTML_NAME @"image_interstitial" diff --git a/CleverTapSDK/InApps/CTInAppDisplayManager.m b/CleverTapSDK/InApps/CTInAppDisplayManager.m index 61c23d95..cf01931f 100644 --- a/CleverTapSDK/InApps/CTInAppDisplayManager.m +++ b/CleverTapSDK/InApps/CTInAppDisplayManager.m @@ -740,7 +740,8 @@ - (BOOL)didHandleInAppTestFromPushNotificaton:(NSDictionary * _Nullable)notifica error:nil] mutableCopy]; // Handle Image Interstitial InApp Test - if (inapp && [notification[CLTAP_INAPP_PREVIEW_TYPE] isEqualToString:CLTAP_INAPP_IMAGE_INTERSTITIAL_TYPE]) { + NSString *inAppPreviewType = notification[CLTAP_INAPP_PREVIEW_TYPE]; + if (inapp && ([inAppPreviewType isEqualToString:CLTAP_INAPP_IMAGE_INTERSTITIAL_TYPE] || [inAppPreviewType isEqualToString:CLTAP_INAPP_ADVANCED_BUILDER_TYPE])) { NSString *config = [inapp valueForKeyPath:CLTAP_INAPP_IMAGE_INTERSTITIAL_CONFIG]; NSString *htmlContent = [self wrapImageInterstitialContent:[CTUtils jsonObjectToString:config]]; if (config && htmlContent) { diff --git a/CleverTapSDK/InApps/resources/image_interstitial.html b/CleverTapSDK/InApps/resources/image_interstitial.html index 3b2d49c8..34e97a86 100644 --- a/CleverTapSDK/InApps/resources/image_interstitial.html +++ b/CleverTapSDK/InApps/resources/image_interstitial.html @@ -1 +1,29 @@ -
+ + + + + + + +
+
+
+ +
+
+
+ + + + From b44db16a79fcf11ee8301660b94c5806851c69cf Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Tue, 19 Nov 2024 16:51:26 +0530 Subject: [PATCH 2/3] - Updated to latest HTML preview template. - Updated wrap ImageInterstitial content to replace without quotes. --- CleverTapSDK/InApps/CTInAppDisplayManager.m | 2 +- CleverTapSDK/InApps/resources/image_interstitial.html | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CleverTapSDK/InApps/CTInAppDisplayManager.m b/CleverTapSDK/InApps/CTInAppDisplayManager.m index cf01931f..e81f558d 100644 --- a/CleverTapSDK/InApps/CTInAppDisplayManager.m +++ b/CleverTapSDK/InApps/CTInAppDisplayManager.m @@ -801,7 +801,7 @@ - (NSString *)wrapImageInterstitialContent:(NSString *)content { if (html && content) { NSArray *parts = [html componentsSeparatedByString:CLTAP_INAPP_HTML_SPLIT]; if ([parts count] == 2) { - return [NSString stringWithFormat:@"%@'%@'%@", parts[0], content, parts[1]]; + return [NSString stringWithFormat:@"%@%@%@", parts[0], content, parts[1]]; } } return nil; diff --git a/CleverTapSDK/InApps/resources/image_interstitial.html b/CleverTapSDK/InApps/resources/image_interstitial.html index 34e97a86..bf59a29d 100644 --- a/CleverTapSDK/InApps/resources/image_interstitial.html +++ b/CleverTapSDK/InApps/resources/image_interstitial.html @@ -22,8 +22,7 @@ - From a9ad294990aafc593e1bf916e17af028e60af036 Mon Sep 17 00:00:00 2001 From: Nikola Zagorchev Date: Tue, 26 Nov 2024 13:00:49 +0200 Subject: [PATCH 3/3] Refactor test push inapp handling --- CleverTapSDK/InApps/CTInAppDisplayManager.m | 78 ++++++++++++--------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/CleverTapSDK/InApps/CTInAppDisplayManager.m b/CleverTapSDK/InApps/CTInAppDisplayManager.m index e81f558d..09caf2d1 100644 --- a/CleverTapSDK/InApps/CTInAppDisplayManager.m +++ b/CleverTapSDK/InApps/CTInAppDisplayManager.m @@ -738,46 +738,29 @@ - (BOOL)didHandleInAppTestFromPushNotificaton:(NSDictionary * _Nullable)notifica NSMutableDictionary *inapp = [[NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil] mutableCopy]; + if (!inapp) { + CleverTapLogDebug(self.config.logLevel, @"%@: Failed to parse the inapp notification as JSON", self); + return YES; + } - // Handle Image Interstitial InApp Test + // Handle Image Interstitial and Advanced Builder InApp Test (Preview) NSString *inAppPreviewType = notification[CLTAP_INAPP_PREVIEW_TYPE]; - if (inapp && ([inAppPreviewType isEqualToString:CLTAP_INAPP_IMAGE_INTERSTITIAL_TYPE] || [inAppPreviewType isEqualToString:CLTAP_INAPP_ADVANCED_BUILDER_TYPE])) { - NSString *config = [inapp valueForKeyPath:CLTAP_INAPP_IMAGE_INTERSTITIAL_CONFIG]; - NSString *htmlContent = [self wrapImageInterstitialContent:[CTUtils jsonObjectToString:config]]; - if (config && htmlContent) { - inapp[@"type"] = CLTAP_INAPP_HTML_TYPE; - id data = inapp[CLTAP_INAPP_DATA_TAG]; - if (data && [data isKindOfClass:[NSDictionary class]]) { - data = [data mutableCopy]; - // Update the html - data[CLTAP_INAPP_HTML] = htmlContent; - } else { - // If data key is not present or it is not a dictionary, - // set it and overwrite it - inapp[CLTAP_INAPP_DATA_TAG] = @{ - CLTAP_INAPP_HTML: htmlContent - }; - } - } else { - CleverTapLogDebug(self.config.logLevel, @"%@: Failed to parse the image-interstitial notification", self); - return YES; + if ([inAppPreviewType isEqualToString:CLTAP_INAPP_IMAGE_INTERSTITIAL_TYPE] || [inAppPreviewType isEqualToString:CLTAP_INAPP_ADVANCED_BUILDER_TYPE]) { + NSMutableDictionary *htmlInapp = [self handleHTMLInAppPreview:inapp]; + if (!htmlInapp) { + return YES; // Failed to handle HTML inapp } + inapp = htmlInapp; } - if (inapp) { - float delay = self.isAppActiveForeground ? 0.5 : 2.0; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - @try { - [self prepareNotificationForDisplay:inapp]; - } @catch (NSException *e) { - CleverTapLogDebug(self.config.logLevel, @"%@: Failed to display the inapp notifcation from payload: %@", self, e.debugDescription); - } - }); - } else { - CleverTapLogDebug(self.config.logLevel, @"%@: Failed to parse the inapp notification as JSON", self); - return YES; - } - + float delay = self.isAppActiveForeground ? 0.5 : 2.0; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + @try { + [self prepareNotificationForDisplay:inapp]; + } @catch (NSException *e) { + CleverTapLogDebug(self.config.logLevel, @"%@: Failed to display the inapp notifcation from payload: %@", self, e.debugDescription); + } + }); } @catch (NSException *e) { CleverTapLogDebug(self.config.logLevel, @"%@: Failed to display the inapp notifcation from payload: %@", self, e.debugDescription); return YES; @@ -807,5 +790,30 @@ - (NSString *)wrapImageInterstitialContent:(NSString *)content { return nil; } +- (NSMutableDictionary *)handleHTMLInAppPreview:(NSMutableDictionary *)inapp { + NSMutableDictionary *htmlInapp = [inapp mutableCopy]; + NSString *config = [htmlInapp valueForKeyPath:CLTAP_INAPP_IMAGE_INTERSTITIAL_CONFIG]; + NSString *htmlContent = [self wrapImageInterstitialContent:[CTUtils jsonObjectToString:config]]; + if (config && htmlContent) { + htmlInapp[@"type"] = CLTAP_INAPP_HTML_TYPE; + id data = htmlInapp[CLTAP_INAPP_DATA_TAG]; + if (data && [data isKindOfClass:[NSDictionary class]]) { + data = [data mutableCopy]; + // Update the html + data[CLTAP_INAPP_HTML] = htmlContent; + } else { + // If data key is not present or it is not a dictionary, + // set it and overwrite it + htmlInapp[CLTAP_INAPP_DATA_TAG] = @{ + CLTAP_INAPP_HTML: htmlContent + }; + } + return htmlInapp; + } else { + CleverTapLogDebug(self.config.logLevel, @"%@: Failed to parse the image-interstitial notification", self); + return nil; + } +} + @end