From e0642cf921c1b284b79b99413589aac9a0c7563e Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Wed, 5 Jan 2022 20:03:54 +0530 Subject: [PATCH 01/28] Carousel auto scroll added --- ...EXCarouselPushNotificationViewController.m | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index a86442f..8b8aa4b 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -38,6 +38,9 @@ @interface WEXCarouselPushNotificationViewController () @property (atomic) NSInteger nextViewIndexToReturn; @property (atomic) BOOL isRendering; +@property (nonatomic, readwrite) NSTimer *scrollTimer; +@property (nonatomic, readwrite) BOOL shouldScroll; + #endif @end @@ -153,6 +156,8 @@ - (void)didReceiveNotification:(UNNotification *)notification API_AVAILABLE(ios( [self initialiseCarouselForNotification:notification]; + [self setupAutoScroll:notification]; + if (downloadedCount < self.carouselItems.count) { [self downloadRemaining:downloadedCount]; @@ -182,6 +187,41 @@ - (void)downloadRemaining:(NSUInteger)downloadFromIndex { } } +- (void)setupAutoScroll:(UNNotification *)notification API_AVAILABLE(ios(10.0)) { + NSString *scrollTime = notification.request.content.userInfo[@"expandableDetails"][@"ast"]; + + [self.scrollTimer invalidate]; + self.scrollTimer = nil; + _shouldScroll = YES; + + NSInteger interval = [scrollTime intValue]; + + // Scroll if interval is more than 0 + if (interval > 0) { + dispatch_async(dispatch_get_main_queue(), ^{ + self.scrollTimer = [NSTimer scheduledTimerWithTimeInterval:interval + target:self + selector:@selector(scrollContent:) + userInfo:notification repeats:YES]; + }); + } +} + +- (void)scrollContent:(NSTimer *)scrollTimer { + if (_shouldScroll) { + [self renderAnimated:(UNNotification *)[scrollTimer userInfo]]; + } else { + [self stopScrollTimer]; + } +} + +- (void)stopScrollTimer { + if (self.scrollTimer) { + [self.scrollTimer invalidate]; + self.scrollTimer = nil; + } +} + - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVAILABLE(ios(10.0)) { [self initialiseViewContainers]; @@ -497,7 +537,7 @@ - (void)slideLeft:(UIView *)view By:(CGFloat)slide { - (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion API_AVAILABLE(ios(10.0)) { - + NSLog(@"PUSHDEBUG: ResponseClicked: %@", response.actionIdentifier); BOOL dismissed = NO; if (self.isRendering) { @@ -505,7 +545,7 @@ - (void)didReceiveNotificationResponse:(UNNotificationResponse *)response } if ([response.actionIdentifier isEqualToString:@"WEG_NEXT"]) { - + _shouldScroll = NO; [self renderAnimated:response.notification]; } else if ([response.actionIdentifier isEqualToString:@"WEG_PREV"]) { From c93df70ef1b53975109f353a880bced4718203ef Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Wed, 5 Jan 2022 23:55:18 +0530 Subject: [PATCH 02/28] Subtitle added to Carousal UI --- Extension App/WEGExtensionApp/Info.plist | 2 +- ...EXCarouselPushNotificationViewController.m | 50 +++++++++++++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Extension App/WEGExtensionApp/Info.plist b/Extension App/WEGExtensionApp/Info.plist index 50aabe6..d08776d 100644 --- a/Extension App/WEGExtensionApp/Info.plist +++ b/Extension App/WEGExtensionApp/Info.plist @@ -53,7 +53,7 @@ WEGEnableLocationAuthorizationRequest IN_USE WEGLicenseCode - 311c5607 + d3a4a436 WEGLogLevel VERBOSE NSAppTransportSecurity diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index 8b8aa4b..fbd6ff4 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -294,23 +294,49 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA if (defaultContentHidden) { + NSString *title = notification.request.content.userInfo[@"expandableDetails"][@"rt"]; + NSString *subtitle = notification.request.content.userInfo[@"expandableDetails"][@"rst"]; + NSString *message = notification.request.content.userInfo[@"expandableDetails"][@"rm"]; + // Add a notification content view for displaying title and body. UIView *notificationContentView = [[UIView alloc] init]; notificationContentView.backgroundColor = [UIColor whiteColor]; UILabel *titleLabel = [[UILabel alloc] init]; - titleLabel.text = notification.request.content.title; - titleLabel.textColor = [UIColor blackColor]; + NSAttributedString *attributedTitle = [[NSMutableAttributedString alloc] + initWithData: [title dataUsingEncoding:NSUnicodeStringEncoding] + options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } + documentAttributes: nil + error: nil + ]; + titleLabel.attributedText = attributedTitle; titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; titleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; + UILabel *subTitleLabel = [[UILabel alloc] init]; + NSAttributedString *attributedSubTitle = [[NSMutableAttributedString alloc] + initWithData: [subtitle dataUsingEncoding:NSUnicodeStringEncoding] + options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } + documentAttributes: nil + error: nil + ]; + subTitleLabel.attributedText = attributedSubTitle; + subTitleLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + subTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; + UILabel *bodyLabel = [[UILabel alloc] init]; - bodyLabel.text = notification.request.content.body; - bodyLabel.textColor = [UIColor blackColor]; + NSAttributedString *attributedBody = [[NSMutableAttributedString alloc] + initWithData: [message dataUsingEncoding:NSUnicodeStringEncoding] + options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } + documentAttributes: nil + error: nil + ]; + bodyLabel.attributedText = attributedBody; bodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:bodyLabel.text]; bodyLabel.numberOfLines = 0; [notificationContentView addSubview:titleLabel]; + [notificationContentView addSubview:subTitleLabel]; [notificationContentView addSubview:bodyLabel]; [self.view addSubview:notificationContentView]; @@ -346,6 +372,20 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA constant:CONTENT_PADDING] .active = YES; + subTitleLabel.translatesAutoresizingMaskIntoConstraints = NO; + [subTitleLabel.leadingAnchor + constraintEqualToAnchor:notificationContentView.leadingAnchor + constant:CONTENT_PADDING] + .active = YES; + [subTitleLabel.trailingAnchor + constraintEqualToAnchor:notificationContentView.trailingAnchor + constant:0 - CONTENT_PADDING] + .active = YES; + [subTitleLabel.topAnchor + constraintEqualToAnchor:titleLabel.bottomAnchor + constant:0] + .active = YES; + bodyLabel.translatesAutoresizingMaskIntoConstraints = NO; [bodyLabel.leadingAnchor constraintEqualToAnchor:notificationContentView.leadingAnchor @@ -355,7 +395,7 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA constraintEqualToAnchor:notificationContentView.trailingAnchor constant:0 - CONTENT_PADDING] .active = YES; - [bodyLabel.topAnchor constraintEqualToAnchor:titleLabel.bottomAnchor + [bodyLabel.topAnchor constraintEqualToAnchor:subTitleLabel.bottomAnchor constant:TITLE_BODY_SPACE] .active = YES; [bodyLabel.bottomAnchor From 5c8dffccc26acc37d6eeeb258c3b748b256cc53e Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Fri, 7 Jan 2022 17:15:03 +0530 Subject: [PATCH 03/28] Temp commit on Rating push --- .../WEXRatingPushNotificationViewController.h | 2 + .../WEXRatingPushNotificationViewController.m | 127 +++++++++++++++++- 2 files changed, 125 insertions(+), 4 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.h b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.h index 4e25ec9..4e93d3e 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.h +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.h @@ -14,6 +14,8 @@ #import "WEXRichPushLayout.h" #endif +#define CONTENT_PADDING 10 +#define TITLE_BODY_SPACE 5 @interface WEXRatingPushNotificationViewController #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index 89b918f..163de34 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -232,6 +232,60 @@ - (void)initialiseViewHierarchy { [mainContentView addSubview:textDisplayView]; + //TODO: Add conditions for lack of rich texts + + UIView *contentSeparator = [[UIView alloc] init]; + contentSeparator.backgroundColor = [UIColor lightGrayColor]; + + [superViewWrapper addSubview:contentSeparator]; + + NSString *richTitle = self.notification.request.content.userInfo[@"expandableDetails"][@"rt"]; + NSString *richSub = self.notification.request.content.userInfo[@"expandableDetails"][@"rst"]; + NSString *richMessage = self.notification.request.content.userInfo[@"expandableDetails"][@"rm"]; + + // Add a notification content view for displaying title and body. + UIView *richContentView = [[UIView alloc] init]; + richContentView.backgroundColor = [UIColor whiteColor]; + + UILabel *richTitleLabel = [[UILabel alloc] init]; + NSAttributedString *attributedTitle = [[NSMutableAttributedString alloc] + initWithData: [richTitle dataUsingEncoding:NSUnicodeStringEncoding] + options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } + documentAttributes: nil + error: nil + ]; + richTitleLabel.attributedText = attributedTitle; + richTitleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; + richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; + + UILabel *richSubLabel = [[UILabel alloc] init]; + NSAttributedString *attributedSubTitle = [[NSMutableAttributedString alloc] + initWithData: [richSub dataUsingEncoding:NSUnicodeStringEncoding] + options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } + documentAttributes: nil + error: nil + ]; + richSubLabel.attributedText = attributedSubTitle; + richSubLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; + + UILabel *richBodyLabel = [[UILabel alloc] init]; + NSAttributedString *attributedBody = [[NSMutableAttributedString alloc] + initWithData: [richMessage dataUsingEncoding:NSUnicodeStringEncoding] + options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } + documentAttributes: nil + error: nil + ]; + richBodyLabel.attributedText = attributedBody; + richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; + richBodyLabel.numberOfLines = 0; + + [richContentView addSubview:richTitleLabel]; + [richContentView addSubview:richSubLabel]; + [richContentView addSubview:richBodyLabel]; + + [superViewWrapper addSubview:richContentView]; + UIView *separator = [[UIView alloc] init]; separator.backgroundColor = [UIColor lightGrayColor]; @@ -315,9 +369,11 @@ - (void)setUpConstraintsWithImageView:(BOOL)imageViewIncluded UIView *superViewWrapper = self.view.subviews[0]; UIView *mainContentView = superViewWrapper.subviews[0]; - UIView *separator = superViewWrapper.subviews[1]; - UIView *starRatingWrapper = superViewWrapper.subviews[2]; - + UIView *contentSeparator = superViewWrapper.subviews[1]; + UIView *richContentView = superViewWrapper.subviews[2]; + UIView *separator = superViewWrapper.subviews[3]; + UIView *starRatingWrapper = superViewWrapper.subviews[4]; + if (@available(iOS 10.0, *)) { superViewWrapper.translatesAutoresizingMaskIntoConstraints = NO; @@ -332,10 +388,22 @@ - (void)setUpConstraintsWithImageView:(BOOL)imageViewIncluded [mainContentView.trailingAnchor constraintEqualToAnchor:mainContentView.superview.trailingAnchor].active = YES; [mainContentView.topAnchor constraintEqualToAnchor:mainContentView.superview.topAnchor].active = YES; + contentSeparator.translatesAutoresizingMaskIntoConstraints = NO; + [contentSeparator.leadingAnchor constraintEqualToAnchor:contentSeparator.superview.leadingAnchor].active = YES; + [contentSeparator.trailingAnchor constraintEqualToAnchor:contentSeparator.superview.trailingAnchor].active = YES; + [contentSeparator.topAnchor constraintEqualToAnchor:mainContentView.bottomAnchor].active = YES; + [contentSeparator.heightAnchor constraintEqualToConstant:0.5].active = YES; + + richContentView.translatesAutoresizingMaskIntoConstraints = NO; + [richContentView.leadingAnchor constraintEqualToAnchor:richContentView.superview.leadingAnchor].active = YES; + [richContentView.trailingAnchor constraintEqualToAnchor:richContentView.superview.trailingAnchor].active = YES; + [richContentView.topAnchor constraintEqualToAnchor:contentSeparator.bottomAnchor].active = YES; +// [richContentView.heightAnchor constraintEqualToConstant:100].active = YES; + separator.translatesAutoresizingMaskIntoConstraints = NO; [separator.leadingAnchor constraintEqualToAnchor:separator.superview.leadingAnchor].active = YES; [separator.trailingAnchor constraintEqualToAnchor:separator.superview.trailingAnchor].active = YES; - [separator.topAnchor constraintEqualToAnchor:mainContentView.bottomAnchor].active = YES; + [separator.topAnchor constraintEqualToAnchor:richContentView.bottomAnchor].active = YES; [separator.heightAnchor constraintEqualToConstant:0.5].active = YES; starRatingWrapper.translatesAutoresizingMaskIntoConstraints = NO; @@ -405,6 +473,57 @@ - (void)setUpConstraintsWithImageView:(BOOL)imageViewIncluded [messageLabel.bottomAnchor constraintEqualToAnchor:textDisplayView.bottomAnchor constant:0-TEXT_PADDING].active = YES; } + // Rich View labels + + UIView *richTitleLabel = richContentView.subviews[0]; + UIView *richSubTitleLabel = richContentView.subviews[1]; + UIView *richBodyLabel = richContentView.subviews[2]; + + richTitleLabel.translatesAutoresizingMaskIntoConstraints = NO; + [richTitleLabel.leadingAnchor + constraintEqualToAnchor:richContentView.leadingAnchor + constant:CONTENT_PADDING] + .active = YES; + [richTitleLabel.trailingAnchor + constraintEqualToAnchor:richContentView.trailingAnchor + constant:0 - CONTENT_PADDING] + .active = YES; + [richTitleLabel.topAnchor + constraintEqualToAnchor:richContentView.topAnchor + constant:CONTENT_PADDING] + .active = YES; + + richSubTitleLabel.translatesAutoresizingMaskIntoConstraints = NO; + [richSubTitleLabel.leadingAnchor + constraintEqualToAnchor:richContentView.leadingAnchor + constant:CONTENT_PADDING] + .active = YES; + [richSubTitleLabel.trailingAnchor + constraintEqualToAnchor:richContentView.trailingAnchor + constant:0 - CONTENT_PADDING] + .active = YES; + [richSubTitleLabel.topAnchor + constraintEqualToAnchor:richTitleLabel.bottomAnchor + constant:TITLE_BODY_SPACE] + .active = YES; + + richBodyLabel.translatesAutoresizingMaskIntoConstraints = NO; + [richBodyLabel.leadingAnchor + constraintEqualToAnchor:richContentView.leadingAnchor + constant:CONTENT_PADDING] + .active = YES; + [richBodyLabel.trailingAnchor + constraintEqualToAnchor:richContentView.trailingAnchor + constant:0 - CONTENT_PADDING] + .active = YES; + [richBodyLabel.topAnchor constraintEqualToAnchor:richSubTitleLabel.bottomAnchor + constant:TITLE_BODY_SPACE] + .active = YES; + [richBodyLabel.bottomAnchor + constraintEqualToAnchor:richContentView.bottomAnchor + constant:-CONTENT_PADDING] + .active = YES; + //Star rating view internal constraints self.labelsWrapper.translatesAutoresizingMaskIntoConstraints = NO; [self.labelsWrapper.topAnchor constraintEqualToAnchor:self.labelsWrapper.superview.topAnchor].active = YES; From e14525bdc1a87d610635e6139f12415f79bd955b Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Wed, 12 Jan 2022 15:50:17 +0530 Subject: [PATCH 04/28] Banner layout update to support rich text customisation --- Extension App/ContentExtension/Info.plist | 49 ++-- .../WEGExtensionApp.xcodeproj/project.pbxproj | 4 + .../WEGExtensionApp/AppDelegate.swift | 13 +- .../WEXBannerPushNotificationViewController.h | 24 ++ .../WEXBannerPushNotificationViewController.m | 242 ++++++++++++++++++ .../WEXRichPushNotificationViewController.m | 4 +- 6 files changed, 307 insertions(+), 29 deletions(-) create mode 100644 WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.h create mode 100644 WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m diff --git a/Extension App/ContentExtension/Info.plist b/Extension App/ContentExtension/Info.plist index 671bd94..3ea36e4 100644 --- a/Extension App/ContentExtension/Info.plist +++ b/Extension App/ContentExtension/Info.plist @@ -20,29 +20,30 @@ 1.0 CFBundleVersion 1 - NSExtension - - NSExtensionAttributes - - UNNotificationExtensionDefaultContentHidden - - UNNotificationExtensionCategory - - WEG_CAROUSEL_V1 - WEG_RATING_V1 - - UNNotificationExtensionInitialContentSizeRatio - 1 - - NSExtensionMainStoryboard - MainInterface - NSExtensionPointIdentifier - com.apple.usernotifications.content-extension - - NSAppTransportSecurity - - NSAllowsArbitraryLoads - - + NSExtension + + NSExtensionAttributes + + UNNotificationExtensionDefaultContentHidden + + UNNotificationExtensionCategory + + WEG_CAROUSEL_V1 + WEG_RATING_V1 + BIG_PICTURE + + UNNotificationExtensionInitialContentSizeRatio + 1 + + NSExtensionMainStoryboard + MainInterface + NSExtensionPointIdentifier + com.apple.usernotifications.content-extension + + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + diff --git a/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj b/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj index a7e32a4..13bfdc0 100644 --- a/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj +++ b/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj @@ -62,6 +62,8 @@ 56A49FB8EB9E003121E4C723 /* Pods-WEGExtensionApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WEGExtensionApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WEGExtensionApp/Pods-WEGExtensionApp.debug.xcconfig"; sourceTree = ""; }; 8167C6E259A361F9B2183151 /* libPods-WEGExtensionApp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WEGExtensionApp.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 8288374F4CC9F6A69DC1929F /* Pods-ContentExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ContentExtension/Pods-ContentExtension.debug.xcconfig"; sourceTree = ""; }; + A6F5D066278D6EA1005A96AA /* WEXBannerPushNotificationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WEXBannerPushNotificationViewController.h; sourceTree = ""; }; + A6F5D067278D6EAE005A96AA /* WEXBannerPushNotificationViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WEXBannerPushNotificationViewController.m; sourceTree = ""; }; B554331A99838E3647290F86 /* Pods-ServiceExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ServiceExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ServiceExtension/Pods-ServiceExtension.debug.xcconfig"; sourceTree = ""; }; BF5C12043F19FA4C36D82355 /* Pods-WEGExtensionApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WEGExtensionApp.release.xcconfig"; path = "Pods/Target Support Files/Pods-WEGExtensionApp/Pods-WEGExtensionApp.release.xcconfig"; sourceTree = ""; }; CF34E9CCD03C284D4C70479B /* Pods-ContentExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentExtension.release.xcconfig"; path = "Pods/Target Support Files/Pods-ContentExtension/Pods-ContentExtension.release.xcconfig"; sourceTree = ""; }; @@ -265,6 +267,8 @@ EC9A3DBA21B6B15300C63B7D /* WEXRichPushNotificationViewController.h */, EC9A3DB721B6B15300C63B7D /* WEXRichPushNotificationViewController.m */, EC9A3DB521B6B15300C63B7D /* WEXRichPushNotificationViewController+Private.h */, + A6F5D066278D6EA1005A96AA /* WEXBannerPushNotificationViewController.h */, + A6F5D067278D6EAE005A96AA /* WEXBannerPushNotificationViewController.m */, ); path = ContentExtension; sourceTree = ""; diff --git a/Extension App/WEGExtensionApp/AppDelegate.swift b/Extension App/WEGExtensionApp/AppDelegate.swift index e900faf..dd77792 100644 --- a/Extension App/WEGExtensionApp/AppDelegate.swift +++ b/Extension App/WEGExtensionApp/AppDelegate.swift @@ -8,6 +8,7 @@ import UIKit import WebEngage +import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -16,11 +17,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - WebEngage.sharedInstance()?.application(application, didFinishLaunchingWithOptions: launchOptions, autoRegister: true) - - NSLog("Extension Demo app launched " + #function) + addCustomPushCategory() + WebEngage.sharedInstance()?.application(application, didFinishLaunchingWithOptions: launchOptions, autoRegister: true) + WebEngage.sharedInstance().user.login("ExtensionQWE1") return true } + + private func addCustomPushCategory() { + let category = UNNotificationCategory.init(identifier: "BIG_PICTURE", actions: [], intentIdentifiers: [], options: []) + UNUserNotificationCenter.current().setNotificationCategories([category]) + } } - diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.h b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.h new file mode 100644 index 0000000..b82e6a3 --- /dev/null +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.h @@ -0,0 +1,24 @@ +// +// WEXBannerPushNotificationViewController.h +// WebEngage +// +// Copyright (c) 2022 Webklipper Technologies Pvt Ltd. All rights reserved. +// + +#import + +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 +#import +#import +#import "WEXRichPushNotificationViewController+Private.h" +#import "WEXRichPushLayout.h" +#endif + +@interface WEXBannerPushNotificationViewController +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 +: WEXRichPushLayout +#else +: NSObject +#endif + +@end diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m new file mode 100644 index 0000000..9319f54 --- /dev/null +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -0,0 +1,242 @@ +// +// WEXBannerPushNotificationViewController.m +// WebEngage +// +// Copyright (c) 2022 Webklipper Technologies Pvt Ltd. All rights reserved. +// + +#import "WEXBannerPushNotificationViewController.h" +#import "WEXRichPushNotificationViewController+Private.h" + +#define CONTENT_PADDING 10 +#define TITLE_BODY_SPACE 5 +#define LANDSCAPE_ASPECT 0.5 + +API_AVAILABLE(ios(10.0)) +@interface WEXBannerPushNotificationViewController () + +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 + +@property (nonatomic) UNNotification *notification; +@property (nonatomic) NSUserDefaults *richPushDefaults; +@property (nonatomic) UIView *labelsContainerView; + +#endif + +@end + +@implementation WEXBannerPushNotificationViewController + +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 + +- (void)didReceiveNotification:(UNNotification *)notification API_AVAILABLE(ios(10.0)) { + self.notification = notification; + + [self initialiseViewHierarchy]; +} + +- (void)initialiseViewHierarchy { + self.view.backgroundColor = [UIColor whiteColor]; + + UIView *superViewWrapper = [[UIView alloc] init]; + [self.view addSubview:superViewWrapper]; + + UIView *mainContentView = [[UIView alloc] init]; + [superViewWrapper addSubview:mainContentView]; + + [self setupBannerImageView]; +} + +- (void)setupBannerImageView { + UIView *superViewWrapper = self.view.subviews[0]; + UIView *mainContentView = superViewWrapper.subviews[0]; + + NSDictionary *expandableDetails = self.notification.request.content.userInfo[@"expandableDetails"]; + + if (expandableDetails[@"image"]) { + if (self.notification.request.content.attachments + && self.notification.request.content.attachments.count > 0) { + + if (@available(iOS 10.0, *)) { + UNNotificationAttachment *attachment = self.notification.request.content.attachments.firstObject; + + if ([attachment.URL startAccessingSecurityScopedResource]) { + NSData *imageData = [NSData dataWithContentsOfFile:attachment.URL.path]; + UIImage *image = [UIImage imageWithData:imageData]; + + [attachment.URL stopAccessingSecurityScopedResource]; + + if (image) { + UIImageView *imageView = [[UIImageView alloc] init]; + imageView.image = image; + imageView.contentMode = UIViewContentModeScaleAspectFill; + [mainContentView addSubview:imageView]; + } + } + } else { + NSLog(@"Expected to be running iOS version 10 or above"); + } + } + } + [self setupLabelsContainer]; +} + +- (void)setupLabelsContainer { + UIView *superViewWrapper = self.view.subviews[0]; + + UIView *richContentView = [[UIView alloc] init]; + richContentView.backgroundColor = [UIColor whiteColor]; + + NSDictionary *expandedDetails = self.notification.request.content.userInfo[@"expandableDetails"]; + NSString *title = expandedDetails[@"rt"]; + NSString *subtitle = expandedDetails[@"rst"]; + NSString *message = expandedDetails[@"rm"]; + + BOOL titlePresent = title && ![title isEqualToString:@""]; + BOOL subTitlePresent = subtitle && ![subtitle isEqualToString:@""]; + BOOL messagePresent = message && ![message isEqualToString:@""]; + + if (!titlePresent) { + title = self.notification.request.content.title; + } + if (!subTitlePresent) { + subtitle = self.notification.request.content.subtitle; + } + if (!messagePresent) { + message = self.notification.request.content.body; + } + + UILabel *richTitleLabel = [[UILabel alloc] init]; + NSAttributedString *attributedTitle = [[NSMutableAttributedString alloc] + initWithData: [title dataUsingEncoding:NSUnicodeStringEncoding] + options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } + documentAttributes: nil + error: nil + ]; + richTitleLabel.attributedText = attributedTitle; + richTitleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; + richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; + + UILabel *richSubLabel = [[UILabel alloc] init]; + NSAttributedString *attributedSubTitle = [[NSMutableAttributedString alloc] + initWithData: [subtitle dataUsingEncoding:NSUnicodeStringEncoding] + options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } + documentAttributes: nil + error: nil + ]; + richSubLabel.attributedText = attributedSubTitle; + richSubLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; + + UILabel *richBodyLabel = [[UILabel alloc] init]; + NSAttributedString *attributedBody = [[NSMutableAttributedString alloc] + initWithData: [message dataUsingEncoding:NSUnicodeStringEncoding] + options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } + documentAttributes: nil + error: nil + ]; + richBodyLabel.attributedText = attributedBody; + richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; + richBodyLabel.numberOfLines = 0; + + [richContentView addSubview:richTitleLabel]; + [richContentView addSubview:richSubLabel]; + [richContentView addSubview:richBodyLabel]; + + [superViewWrapper addSubview:richContentView]; + + [self setupConstraints]; +} + +- (void)setupConstraints { + UIView *superViewWrapper = self.view.subviews[0]; + UIView *mainContentView = superViewWrapper.subviews[0]; + UIView *richContentView = superViewWrapper.subviews[1]; + + if (@available(iOS 10.0, *)) { + superViewWrapper.translatesAutoresizingMaskIntoConstraints = NO; + [superViewWrapper.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES; + [superViewWrapper.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES; + [superViewWrapper.topAnchor constraintEqualToAnchor:self.view.topAnchor].active = YES; + [superViewWrapper.bottomAnchor constraintEqualToAnchor:richContentView.bottomAnchor].active = YES; + + //Top level view constraints + mainContentView.translatesAutoresizingMaskIntoConstraints = NO; + [mainContentView.leadingAnchor constraintEqualToAnchor:mainContentView.superview.leadingAnchor].active = YES; + [mainContentView.trailingAnchor constraintEqualToAnchor:mainContentView.superview.trailingAnchor].active = YES; + [mainContentView.topAnchor constraintEqualToAnchor:mainContentView.superview.topAnchor].active = YES; + + richContentView.translatesAutoresizingMaskIntoConstraints = NO; + [richContentView.leadingAnchor constraintEqualToAnchor:richContentView.superview.leadingAnchor].active = YES; + [richContentView.trailingAnchor constraintEqualToAnchor:richContentView.superview.trailingAnchor].active = YES; + [richContentView.topAnchor constraintEqualToAnchor:mainContentView.bottomAnchor].active = YES; + + [self.viewController.bottomLayoutGuide.topAnchor constraintEqualToAnchor:superViewWrapper.bottomAnchor].active = YES; + + //Main Content View ImageView constraints + UIImageView *imageView = mainContentView.subviews[0]; + imageView.translatesAutoresizingMaskIntoConstraints = NO; + [imageView.topAnchor constraintEqualToAnchor:mainContentView.topAnchor].active = YES; + [imageView.leadingAnchor constraintEqualToAnchor:mainContentView.leadingAnchor].active = YES; + [imageView.trailingAnchor constraintEqualToAnchor:mainContentView.trailingAnchor].active = YES; + [imageView.heightAnchor constraintEqualToAnchor:imageView.widthAnchor multiplier:LANDSCAPE_ASPECT].active = YES; + [mainContentView.bottomAnchor constraintEqualToAnchor:imageView.bottomAnchor].active = YES; + + //Rich View labels + UIView *richTitleLabel = richContentView.subviews[0]; + UIView *richSubTitleLabel = richContentView.subviews[1]; + UIView *richBodyLabel = richContentView.subviews[2]; + + richTitleLabel.translatesAutoresizingMaskIntoConstraints = NO; + [richTitleLabel.leadingAnchor + constraintEqualToAnchor:richContentView.leadingAnchor + constant:CONTENT_PADDING] + .active = YES; + [richTitleLabel.trailingAnchor + constraintEqualToAnchor:richContentView.trailingAnchor + constant:0 - CONTENT_PADDING] + .active = YES; + [richTitleLabel.topAnchor + constraintEqualToAnchor:richContentView.topAnchor + constant:CONTENT_PADDING] + .active = YES; + + richSubTitleLabel.translatesAutoresizingMaskIntoConstraints = NO; + [richSubTitleLabel.leadingAnchor + constraintEqualToAnchor:richContentView.leadingAnchor + constant:CONTENT_PADDING] + .active = YES; + [richSubTitleLabel.trailingAnchor + constraintEqualToAnchor:richContentView.trailingAnchor + constant:0 - CONTENT_PADDING] + .active = YES; + [richSubTitleLabel.topAnchor + constraintEqualToAnchor:richTitleLabel.bottomAnchor + constant:TITLE_BODY_SPACE] + .active = YES; + + richBodyLabel.translatesAutoresizingMaskIntoConstraints = NO; + [richBodyLabel.leadingAnchor + constraintEqualToAnchor:richContentView.leadingAnchor + constant:CONTENT_PADDING] + .active = YES; + [richBodyLabel.trailingAnchor + constraintEqualToAnchor:richContentView.trailingAnchor + constant:0 - CONTENT_PADDING] + .active = YES; + [richBodyLabel.topAnchor constraintEqualToAnchor:richSubTitleLabel.bottomAnchor + constant:TITLE_BODY_SPACE] + .active = YES; + [richBodyLabel.bottomAnchor + constraintEqualToAnchor:richContentView.bottomAnchor + constant:-CONTENT_PADDING] + .active = YES; + } else { + NSLog(@"Expected to be running iOS version 10 or above"); + } +} + +#endif + +@end + diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index a0a963c..34a549c 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -9,6 +9,7 @@ #import "WEXRichPushNotificationViewController+Private.h" #import "WEXCarouselPushNotificationViewController.h" #import "WEXRatingPushNotificationViewController.h" +#import "WEXBannerPushNotificationViewController.h" #import "WEXRichPushLayout.h" #import #import @@ -126,8 +127,9 @@ - (WEXRichPushLayout *)layoutForStyle:(NSString *)style { return [[WEXCarouselPushNotificationViewController alloc] initWithNotificationViewController:self]; } else if (style && [style isEqualToString:@"RATING_V1"]) { return [[WEXRatingPushNotificationViewController alloc] initWithNotificationViewController:self]; + } else if (style && [style isEqualToString:@"BIG_PICTURE"]) { + return [[WEXBannerPushNotificationViewController alloc] initWithNotificationViewController:self]; } - return nil; } From 2091a7c6169903cf0b6c333079b094988b1d8cfa Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Wed, 12 Jan 2022 16:19:10 +0530 Subject: [PATCH 05/28] Banner image aspect issue fixed --- .../WEXBannerPushNotificationViewController.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m index 9319f54..a762963 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -176,10 +176,17 @@ - (void)setupConstraints { //Main Content View ImageView constraints UIImageView *imageView = mainContentView.subviews[0]; imageView.translatesAutoresizingMaskIntoConstraints = NO; + + UIImage *bannerImage = imageView.image; + CGFloat imageAspect = LANDSCAPE_ASPECT; + if (bannerImage && bannerImage.size.height != 0) { + imageAspect = bannerImage.size.height/bannerImage.size.width; + } + [imageView.topAnchor constraintEqualToAnchor:mainContentView.topAnchor].active = YES; [imageView.leadingAnchor constraintEqualToAnchor:mainContentView.leadingAnchor].active = YES; [imageView.trailingAnchor constraintEqualToAnchor:mainContentView.trailingAnchor].active = YES; - [imageView.heightAnchor constraintEqualToAnchor:imageView.widthAnchor multiplier:LANDSCAPE_ASPECT].active = YES; + [imageView.heightAnchor constraintEqualToAnchor:imageView.widthAnchor multiplier:imageAspect].active = YES; [mainContentView.bottomAnchor constraintEqualToAnchor:imageView.bottomAnchor].active = YES; //Rich View labels From e52d4831a629cfa3d6111921104c93b869bb34d9 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Wed, 12 Jan 2022 16:48:03 +0530 Subject: [PATCH 06/28] - Default text added for customised text labels - Crash fixed caused by alignment util function --- .../WEXRatingPushNotificationViewController.m | 15 ++++++++++++++- .../WEXRichPushNotificationViewController.m | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index 163de34..6829c6c 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -243,6 +243,20 @@ - (void)initialiseViewHierarchy { NSString *richSub = self.notification.request.content.userInfo[@"expandableDetails"][@"rst"]; NSString *richMessage = self.notification.request.content.userInfo[@"expandableDetails"][@"rm"]; + BOOL isRichTitle = richTitle && ![richTitle isEqualToString:@""]; + BOOL isRichSubtitle = richSub && ![richSub isEqualToString:@""]; + BOOL isRichMessage = richMessage && ![richMessage isEqualToString:@""]; + + if (!isRichTitle) { + richTitle = self.notification.request.content.title; + } + if (!isRichSubtitle) { + richSub = self.notification.request.content.subtitle; + } + if (!isRichMessage) { + richMessage = self.notification.request.content.body; + } + // Add a notification content view for displaying title and body. UIView *richContentView = [[UIView alloc] init]; richContentView.backgroundColor = [UIColor whiteColor]; @@ -398,7 +412,6 @@ - (void)setUpConstraintsWithImageView:(BOOL)imageViewIncluded [richContentView.leadingAnchor constraintEqualToAnchor:richContentView.superview.leadingAnchor].active = YES; [richContentView.trailingAnchor constraintEqualToAnchor:richContentView.superview.trailingAnchor].active = YES; [richContentView.topAnchor constraintEqualToAnchor:contentSeparator.bottomAnchor].active = YES; -// [richContentView.heightAnchor constraintEqualToConstant:100].active = YES; separator.translatesAutoresizingMaskIntoConstraints = NO; [separator.leadingAnchor constraintEqualToAnchor:separator.superview.leadingAnchor].active = YES; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index a0a963c..453644d 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -231,6 +231,10 @@ - (void)setCTAWithId:(NSString *)ctaId andLink:(NSString *)actionLink { } - (NSTextAlignment)naturalTextAligmentForText:(NSString*) text{ + if (text == (id)[NSNull null] || text.length == 0 ) { + return NSTextAlignmentLeft; + } + NSArray *tagschemes = [NSArray arrayWithObjects:NSLinguisticTagSchemeLanguage, nil]; NSLinguisticTagger *tagger = [[NSLinguisticTagger alloc] initWithTagSchemes:tagschemes options:0]; [tagger setString:text]; From a0546f9f5bd017ad6e7bf2fe7f4e05d15090a741 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Thu, 20 Jan 2022 16:16:29 +0530 Subject: [PATCH 07/28] Background colour added for Carousal and Rating layout --- ...EXCarouselPushNotificationViewController.m | 18 ++++++++++++- .../WEXRatingPushNotificationViewController.m | 4 ++- ...chPushNotificationViewController+Private.h | 2 ++ .../WEXRichPushNotificationViewController.m | 26 ++++++++++++++++--- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index fbd6ff4..857d704 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -298,9 +298,25 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA NSString *subtitle = notification.request.content.userInfo[@"expandableDetails"][@"rst"]; NSString *message = notification.request.content.userInfo[@"expandableDetails"][@"rm"]; + BOOL isRichTitle = title && ![title isEqualToString:@""]; + BOOL isRichSubtitle = subtitle && ![subtitle isEqualToString:@""]; + BOOL isRichMessage = message && ![message isEqualToString:@""]; + + if (!isRichTitle) { + title = self.notification.request.content.title; + } + if (!isRichSubtitle) { + subtitle = self.notification.request.content.subtitle; + } + if (!isRichMessage) { + message = self.notification.request.content.body; + } + + NSString *colorHex = notification.request.content.userInfo[@"expandableDetails"][@"bckColor"]; + // Add a notification content view for displaying title and body. UIView *notificationContentView = [[UIView alloc] init]; - notificationContentView.backgroundColor = [UIColor whiteColor]; + notificationContentView.backgroundColor = [self.viewController colorFromHexString:colorHex]; UILabel *titleLabel = [[UILabel alloc] init]; NSAttributedString *attributedTitle = [[NSMutableAttributedString alloc] diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index 6829c6c..b8785a5 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -257,9 +257,11 @@ - (void)initialiseViewHierarchy { richMessage = self.notification.request.content.body; } + NSString *colorHex = self.notification.request.content.userInfo[@"expandableDetails"][@"bckColor"]; + // Add a notification content view for displaying title and body. UIView *richContentView = [[UIView alloc] init]; - richContentView.backgroundColor = [UIColor whiteColor]; + richContentView.backgroundColor = [self.viewController colorFromHexString:colorHex]; UILabel *richTitleLabel = [[UILabel alloc] init]; NSAttributedString *attributedTitle = [[NSMutableAttributedString alloc] diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h index 8d2d3b4..b5de898 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h @@ -26,6 +26,8 @@ - (NSTextAlignment)naturalTextAligmentForText:(NSString*) text; +- (UIColor *)colorFromHexString:(NSString *)hexString; + #endif @end diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index 453644d..087eef7 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -215,9 +215,9 @@ - (void)addEventWithName:(NSString *)eventName if ([category isEqualToString:@"system"]) { [WEXAnalytics trackEventWithName:[@"we_" stringByAppendingString:eventName] andValue:@{ - @"system_data_overrides": systemData ? systemData : @{}, - @"event_data_overrides": customDataDictionary - }]; + @"system_data_overrides": systemData ? systemData : @{}, + @"event_data_overrides": customDataDictionary + }]; } else { [WEXAnalytics trackEventWithName:eventName andValue:customDataDictionary]; } @@ -230,7 +230,7 @@ - (void)setCTAWithId:(NSString *)ctaId andLink:(NSString *)actionLink { [self updateActivityWithObject:cta forKey:@"cta"]; } -- (NSTextAlignment)naturalTextAligmentForText:(NSString*) text{ +- (NSTextAlignment)naturalTextAligmentForText:(NSString*)text { if (text == (id)[NSNull null] || text.length == 0 ) { return NSTextAlignmentLeft; } @@ -246,6 +246,24 @@ - (NSTextAlignment)naturalTextAligmentForText:(NSString*) text{ } } +- (UIColor *)colorFromHexString:(NSString *)hexString { + if (hexString == (id)[NSNull null] || hexString.length == 0) { + return UIColor.whiteColor; + } + + unsigned rgbValue = 0; + NSScanner *scanner = [NSScanner scannerWithString:hexString]; + + if ([hexString hasPrefix:@"#"]) { + [scanner setScanLocation:1]; // bypass '#' character + } else { + [scanner setScanLocation:0]; + } + + [scanner scanHexInt:&rgbValue]; + return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; +} + #endif @end From 5d9a7bfa39b55b8a2ebafa186eb4572f18c75b45 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Thu, 20 Jan 2022 16:24:52 +0530 Subject: [PATCH 08/28] Label pading update --- .../WEXCarouselPushNotificationViewController.m | 3 ++- .../WEXRatingPushNotificationViewController.m | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index 857d704..9608662 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -348,6 +348,7 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA error: nil ]; bodyLabel.attributedText = attributedBody; + bodyLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; bodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:bodyLabel.text]; bodyLabel.numberOfLines = 0; @@ -412,7 +413,7 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA constant:0 - CONTENT_PADDING] .active = YES; [bodyLabel.topAnchor constraintEqualToAnchor:subTitleLabel.bottomAnchor - constant:TITLE_BODY_SPACE] + constant:0] .active = YES; [bodyLabel.bottomAnchor constraintEqualToAnchor:notificationContentView.bottomAnchor diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index b8785a5..dce8774 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -293,6 +293,7 @@ - (void)initialiseViewHierarchy { error: nil ]; richBodyLabel.attributedText = attributedBody; + richBodyLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; richBodyLabel.numberOfLines = 0; @@ -519,7 +520,7 @@ - (void)setUpConstraintsWithImageView:(BOOL)imageViewIncluded .active = YES; [richSubTitleLabel.topAnchor constraintEqualToAnchor:richTitleLabel.bottomAnchor - constant:TITLE_BODY_SPACE] + constant:0] .active = YES; richBodyLabel.translatesAutoresizingMaskIntoConstraints = NO; @@ -532,7 +533,7 @@ - (void)setUpConstraintsWithImageView:(BOOL)imageViewIncluded constant:0 - CONTENT_PADDING] .active = YES; [richBodyLabel.topAnchor constraintEqualToAnchor:richSubTitleLabel.bottomAnchor - constant:TITLE_BODY_SPACE] + constant:0] .active = YES; [richBodyLabel.bottomAnchor constraintEqualToAnchor:richContentView.bottomAnchor From ca93d21360eb39a6b02914f281e72c8806461305 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Thu, 20 Jan 2022 20:21:48 +0530 Subject: [PATCH 09/28] - Provision added for font size using html - Code refector --- ...EXCarouselPushNotificationViewController.m | 29 ++---------- .../WEXRatingPushNotificationViewController.m | 34 +++----------- ...chPushNotificationViewController+Private.h | 4 +- .../WEXRichPushNotificationViewController.m | 47 ++++++++++++++++++- 4 files changed, 58 insertions(+), 56 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index 9608662..8b96853 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -316,39 +316,18 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA // Add a notification content view for displaying title and body. UIView *notificationContentView = [[UIView alloc] init]; - notificationContentView.backgroundColor = [self.viewController colorFromHexString:colorHex]; + notificationContentView.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; UILabel *titleLabel = [[UILabel alloc] init]; - NSAttributedString *attributedTitle = [[NSMutableAttributedString alloc] - initWithData: [title dataUsingEncoding:NSUnicodeStringEncoding] - options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } - documentAttributes: nil - error: nil - ]; - titleLabel.attributedText = attributedTitle; - titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; + titleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES]; titleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; UILabel *subTitleLabel = [[UILabel alloc] init]; - NSAttributedString *attributedSubTitle = [[NSMutableAttributedString alloc] - initWithData: [subtitle dataUsingEncoding:NSUnicodeStringEncoding] - options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } - documentAttributes: nil - error: nil - ]; - subTitleLabel.attributedText = attributedSubTitle; - subTitleLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + subTitleLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO]; subTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; UILabel *bodyLabel = [[UILabel alloc] init]; - NSAttributedString *attributedBody = [[NSMutableAttributedString alloc] - initWithData: [message dataUsingEncoding:NSUnicodeStringEncoding] - options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } - documentAttributes: nil - error: nil - ]; - bodyLabel.attributedText = attributedBody; - bodyLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + bodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; bodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:bodyLabel.text]; bodyLabel.numberOfLines = 0; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index dce8774..fd04280 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -261,39 +261,18 @@ - (void)initialiseViewHierarchy { // Add a notification content view for displaying title and body. UIView *richContentView = [[UIView alloc] init]; - richContentView.backgroundColor = [self.viewController colorFromHexString:colorHex]; + richContentView.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; UILabel *richTitleLabel = [[UILabel alloc] init]; - NSAttributedString *attributedTitle = [[NSMutableAttributedString alloc] - initWithData: [richTitle dataUsingEncoding:NSUnicodeStringEncoding] - options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } - documentAttributes: nil - error: nil - ]; - richTitleLabel.attributedText = attributedTitle; - richTitleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; + richTitleLabel.attributedText = [self.viewController getHtmlParsedString:richTitle isTitle:YES]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; UILabel *richSubLabel = [[UILabel alloc] init]; - NSAttributedString *attributedSubTitle = [[NSMutableAttributedString alloc] - initWithData: [richSub dataUsingEncoding:NSUnicodeStringEncoding] - options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } - documentAttributes: nil - error: nil - ]; - richSubLabel.attributedText = attributedSubTitle; - richSubLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + richSubLabel.attributedText = [self.viewController getHtmlParsedString:richSub isTitle:NO]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; UILabel *richBodyLabel = [[UILabel alloc] init]; - NSAttributedString *attributedBody = [[NSMutableAttributedString alloc] - initWithData: [richMessage dataUsingEncoding:NSUnicodeStringEncoding] - options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } - documentAttributes: nil - error: nil - ]; - richBodyLabel.attributedText = attributedBody; - richBodyLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + richBodyLabel.attributedText = [self.viewController getHtmlParsedString:richMessage isTitle:NO]; richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; richBodyLabel.numberOfLines = 0; @@ -304,13 +283,12 @@ - (void)initialiseViewHierarchy { [superViewWrapper addSubview:richContentView]; UIView *separator = [[UIView alloc] init]; - separator.backgroundColor = [UIColor lightGrayColor]; + separator.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.lightGrayColor]; [superViewWrapper addSubview:separator]; UIView *starRatingView = [[UIView alloc] init]; - starRatingView.backgroundColor = [UIColor whiteColor]; - + starRatingView.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; self.labelsWrapper = [[UIView alloc] init]; self.unselectedLabel = [[UILabel alloc] init]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h index b5de898..ec92c59 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h @@ -26,7 +26,9 @@ - (NSTextAlignment)naturalTextAligmentForText:(NSString*) text; -- (UIColor *)colorFromHexString:(NSString *)hexString; +- (UIColor *)colorFromHexString:(NSString *)hexString defaultColor:(UIColor *)defaultColor; + +- (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL)isTitle; #endif diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index 087eef7..8b9211e 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -246,9 +246,9 @@ - (NSTextAlignment)naturalTextAligmentForText:(NSString*)text { } } -- (UIColor *)colorFromHexString:(NSString *)hexString { +- (UIColor *)colorFromHexString:(NSString *)hexString defaultColor:(UIColor *)defaultColor { if (hexString == (id)[NSNull null] || hexString.length == 0) { - return UIColor.whiteColor; + return defaultColor; } unsigned rgbValue = 0; @@ -264,6 +264,49 @@ - (UIColor *)colorFromHexString:(NSString *)hexString { return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; } +- (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL)isTitle { + NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] + initWithData: [textString dataUsingEncoding:NSUnicodeStringEncoding] + options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } + documentAttributes: nil + error: nil + ]; + + BOOL containsHTML = [self containsHTML:textString]; + BOOL containsFontSize = [textString rangeOfString:@"font-size"].location != NSNotFound; + BOOL containsStrong = [textString rangeOfString:@""].location != NSNotFound; + + UIFont *defaultFont = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + UIFont *boldFont = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; + + /* + If html string doesn't contain font-size, + then setting default based on Strong tag or title position + */ + + if (containsHTML && containsFontSize == NO) { + if (containsStrong) { + [attributedString addAttribute:NSFontAttributeName value:boldFont range:NSMakeRange(0, attributedString.length)]; + } else { + [attributedString addAttribute:NSFontAttributeName value:defaultFont range:NSMakeRange(0, attributedString.length)]; + } + + } else if (containsHTML == NO) { + if (isTitle) { + [attributedString addAttribute:NSFontAttributeName value:boldFont range:NSMakeRange(0, attributedString.length)]; + } else { + [attributedString addAttribute:NSFontAttributeName value:defaultFont range:NSMakeRange(0, attributedString.length)]; + } + } + return attributedString; +} + +- (BOOL)containsHTML:(NSString *)value { + NSString *htmlRegex = @"<[a-z][\\s\\S]*>"; + NSPredicate *htmlText = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", htmlRegex]; + return [htmlText evaluateWithObject:value]; +} + #endif @end From d31b0f435b46d8f5c89015b3d1550986cd929557 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Fri, 21 Jan 2022 12:02:54 +0530 Subject: [PATCH 10/28] - Rich text issue fix caused by overriding of string attributes - Background colour issue fixed for Carousal portrait --- .../WEGExtensionApp.xcodeproj/project.pbxproj | 4 +++ .../NSMutableAttributedString+Additions.h | 15 +++++++++ .../NSMutableAttributedString+Additions.m | 32 +++++++++++++++++++ ...EXCarouselPushNotificationViewController.m | 12 ++++--- .../WEXRichPushNotificationViewController.m | 6 ++-- 5 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h create mode 100644 WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m diff --git a/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj b/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj index a7e32a4..af90eb5 100644 --- a/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj +++ b/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj @@ -62,6 +62,8 @@ 56A49FB8EB9E003121E4C723 /* Pods-WEGExtensionApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WEGExtensionApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WEGExtensionApp/Pods-WEGExtensionApp.debug.xcconfig"; sourceTree = ""; }; 8167C6E259A361F9B2183151 /* libPods-WEGExtensionApp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WEGExtensionApp.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 8288374F4CC9F6A69DC1929F /* Pods-ContentExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ContentExtension/Pods-ContentExtension.debug.xcconfig"; sourceTree = ""; }; + A6DDEE99279A7A8D007FADE1 /* NSMutableAttributedString+Additions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableAttributedString+Additions.h"; sourceTree = ""; }; + A6DDEE9A279A7B22007FADE1 /* NSMutableAttributedString+Additions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableAttributedString+Additions.m"; sourceTree = ""; }; B554331A99838E3647290F86 /* Pods-ServiceExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ServiceExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ServiceExtension/Pods-ServiceExtension.debug.xcconfig"; sourceTree = ""; }; BF5C12043F19FA4C36D82355 /* Pods-WEGExtensionApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WEGExtensionApp.release.xcconfig"; path = "Pods/Target Support Files/Pods-WEGExtensionApp/Pods-WEGExtensionApp.release.xcconfig"; sourceTree = ""; }; CF34E9CCD03C284D4C70479B /* Pods-ContentExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentExtension.release.xcconfig"; path = "Pods/Target Support Files/Pods-ContentExtension/Pods-ContentExtension.release.xcconfig"; sourceTree = ""; }; @@ -265,6 +267,8 @@ EC9A3DBA21B6B15300C63B7D /* WEXRichPushNotificationViewController.h */, EC9A3DB721B6B15300C63B7D /* WEXRichPushNotificationViewController.m */, EC9A3DB521B6B15300C63B7D /* WEXRichPushNotificationViewController+Private.h */, + A6DDEE99279A7A8D007FADE1 /* NSMutableAttributedString+Additions.h */, + A6DDEE9A279A7B22007FADE1 /* NSMutableAttributedString+Additions.m */, ); path = ContentExtension; sourceTree = ""; diff --git a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h new file mode 100644 index 0000000..9e0abe7 --- /dev/null +++ b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h @@ -0,0 +1,15 @@ +// +// NSMutableAttributedString+Additions.h +// WebEngage +// +// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved. +// + +#import + + +@interface NSMutableAttributedString (Additions) + +- (void)setFontFaceWithFont:(UIFont *)font; + +@end diff --git a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m new file mode 100644 index 0000000..33ac632 --- /dev/null +++ b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m @@ -0,0 +1,32 @@ +// +// NSMutableAttributedString+Additions.m +// WebEngage +// +// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved. +// + +#import +#import "NSMutableAttributedString+Additions.h" + +@implementation NSMutableAttributedString (Additions) + +- (void)setFontFaceWithFont:(UIFont *)font { + [self beginEditing]; + [self enumerateAttribute:NSFontAttributeName + inRange:NSMakeRange(0, self.length) + options:0 + usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { + + UIFont *oldFont = (UIFont *)value; + UIFontDescriptor *newFontDescriptor = [[oldFont.fontDescriptor fontDescriptorWithFamily:font.familyName] fontDescriptorWithSymbolicTraits:oldFont.fontDescriptor.symbolicTraits]; + UIFont *newFont = [UIFont fontWithDescriptor:newFontDescriptor size:font.pointSize]; + + if (newFont) { + [self removeAttribute:NSFontAttributeName range:range]; + [self addAttribute:NSFontAttributeName value:newFont range:range]; + } + }]; + [self endEditing]; +} + +@end diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index 8b96853..b78a3d8 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -237,6 +237,10 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA // for portrait float superViewHeight = viewHeight + 2 * verticalMargins; + NSString *colorHex = notification.request.content.userInfo[@"expandableDetails"][@"bckColor"]; + self.view.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; + self.viewController.view.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; + NSString *mode = notification.request.content.userInfo[@"expandableDetails"][@"mode"]; BOOL isPortrait = mode && [mode isEqualToString:@"portrait"]; @@ -283,7 +287,7 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA topSeparator.backgroundColor = [UIColor lightGrayColor]; UIView *bottomSeparator = [[UIView alloc] initWithFrame:CGRectMake(0.0, superViewHeight - 0.5, superViewWidth, 0.5)]; - bottomSeparator.backgroundColor = [UIColor lightGrayColor]; + bottomSeparator.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.lightGrayColor]; NSDictionary *extensionAttributes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSExtension"][@"NSExtensionAttributes"]; @@ -312,8 +316,6 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA message = self.notification.request.content.body; } - NSString *colorHex = notification.request.content.userInfo[@"expandableDetails"][@"bckColor"]; - // Add a notification content view for displaying title and body. UIView *notificationContentView = [[UIView alloc] init]; notificationContentView.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; @@ -640,6 +642,8 @@ - (UIView *)viewAtPosition:(NSInteger)index { self.notification.request.content.userInfo[@"expandableDetails"][@"mode"]; BOOL isPortrait = mode && [mode isEqualToString:@"portrait"]; + NSString *colorHex = self.notification.request.content.userInfo[@"expandableDetails"][@"bckColor"]; + if (!isPortrait) { viewWidth = superViewWidth; viewHeight = viewWidth * LANDSCAPE_ASPECT; @@ -650,7 +654,7 @@ - (UIView *)viewAtPosition:(NSInteger)index { UIView *viewContainer = viewToReturn; UIImage *image = self.images[index]; - viewContainer.backgroundColor = [UIColor lightGrayColor]; + viewContainer.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.lightGrayColor]; UIImageView *imageView = self.imageViews[cachedViewIndex]; imageView.frame = CGRectMake(0.0, 0.0, viewWidth, viewHeight); diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index 8b9211e..6d6ee7f 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -12,7 +12,7 @@ #import "WEXRichPushLayout.h" #import #import - +#import "NSMutableAttributedString+Additions.h" API_AVAILABLE(ios(10.0)) @interface WEXRichPushNotificationViewController () @@ -286,9 +286,9 @@ - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL if (containsHTML && containsFontSize == NO) { if (containsStrong) { - [attributedString addAttribute:NSFontAttributeName value:boldFont range:NSMakeRange(0, attributedString.length)]; + [attributedString setFontFaceWithFont:boldFont]; } else { - [attributedString addAttribute:NSFontAttributeName value:defaultFont range:NSMakeRange(0, attributedString.length)]; + [attributedString setFontFaceWithFont:defaultFont]; } } else if (containsHTML == NO) { From 4fa59e825d5b67631b257e86cd05e7bcbb6b040b Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Fri, 21 Jan 2022 12:23:42 +0530 Subject: [PATCH 11/28] AutoScroll time interval is now based on miliseconds --- .../WEXCarouselPushNotificationViewController.m | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index b78a3d8..fd9eff6 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -190,16 +190,21 @@ - (void)downloadRemaining:(NSUInteger)downloadFromIndex { - (void)setupAutoScroll:(UNNotification *)notification API_AVAILABLE(ios(10.0)) { NSString *scrollTime = notification.request.content.userInfo[@"expandableDetails"][@"ast"]; + if (scrollTime == (id)[NSNull null] || scrollTime.length == 0) { + return; + } + [self.scrollTimer invalidate]; self.scrollTimer = nil; - _shouldScroll = YES; - NSInteger interval = [scrollTime intValue]; + float intervalInMili = [scrollTime floatValue]; + float intervalSeconds = intervalInMili/1000.0; // Scroll if interval is more than 0 - if (interval > 0) { + if (intervalSeconds > 0) { + _shouldScroll = YES; dispatch_async(dispatch_get_main_queue(), ^{ - self.scrollTimer = [NSTimer scheduledTimerWithTimeInterval:interval + self.scrollTimer = [NSTimer scheduledTimerWithTimeInterval:intervalSeconds target:self selector:@selector(scrollContent:) userInfo:notification repeats:YES]; From 0822ac7a320977827614d44901391efa4b485532 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Fri, 21 Jan 2022 13:50:42 +0530 Subject: [PATCH 12/28] Removed extra line caused by HTML parser in attributedString --- .../WEXRichPushNotificationViewController.m | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index 6d6ee7f..0997360 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -298,7 +298,7 @@ - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL [attributedString addAttribute:NSFontAttributeName value:defaultFont range:NSMakeRange(0, attributedString.length)]; } } - return attributedString; + return [self cleanStringForExtraLine:attributedString]; } - (BOOL)containsHTML:(NSString *)value { @@ -307,6 +307,23 @@ - (BOOL)containsHTML:(NSString *)value { return [htmlText evaluateWithObject:value]; } +/* + Cleaning required as HTML parser sometimes add extra newLine at the end of parsed string, + Title, Subtitle has single line restriction from apple + Desc can have mulitple lines + So even if remove newLine from title and subtitle, It won't affect UI + */ + +- (NSAttributedString *)cleanStringForExtraLine:(NSMutableAttributedString *)attributedString { + NSMutableAttributedString *mutableAttributedString = attributedString; + NSString *currentString = attributedString.string; + if ([currentString hasSuffix:@"\n"]) { + currentString = [currentString substringToIndex:[currentString length]-1]; + } + [mutableAttributedString.mutableString setString:currentString]; + return mutableAttributedString;; +} + #endif @end From daf28a53b6608e4e022eae10d034060882d847f4 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Mon, 24 Jan 2022 22:54:19 +0530 Subject: [PATCH 13/28] Trailing whitespace removed --- .../NSMutableAttributedString+Additions.h | 2 ++ .../NSMutableAttributedString+Additions.m | 15 +++++++++++ .../WEXRichPushNotificationViewController.m | 26 +++++-------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h index 9e0abe7..7552e96 100644 --- a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h +++ b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h @@ -12,4 +12,6 @@ - (void)setFontFaceWithFont:(UIFont *)font; +- (void)trimWhiteSpace; + @end diff --git a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m index 33ac632..6d8acc6 100644 --- a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m +++ b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m @@ -29,4 +29,19 @@ - (void)setFontFaceWithFont:(UIFont *)font { [self endEditing]; } +- (void)trimWhiteSpace { + NSCharacterSet *legalChars = [[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet]; + NSRange startRange = [self.string rangeOfCharacterFromSet: legalChars]; + NSRange endRange = [self.string rangeOfCharacterFromSet: legalChars options:NSBackwardsSearch]; + if (startRange.location == NSNotFound || endRange.location == NSNotFound) { + // there are no legal characters in self --- it is ALL whitespace, and so we 'trim' everything leaving an empty string + [self setAttributedString:[NSAttributedString new]]; + } + else { + NSUInteger startLocation = NSMaxRange(startRange), endLocation = endRange.location; + NSRange range = NSMakeRange(startLocation - 1, endLocation - startLocation + 2); + [self setAttributedString:[self attributedSubstringFromRange:range]]; + } +} + @end diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index 0997360..77e0cb6 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -278,7 +278,7 @@ - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL UIFont *defaultFont = [UIFont systemFontOfSize:[UIFont labelFontSize]]; UIFont *boldFont = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; - + /* If html string doesn't contain font-size, then setting default based on Strong tag or title position @@ -290,6 +290,7 @@ - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL } else { [attributedString setFontFaceWithFont:defaultFont]; } + [attributedString trimWhiteSpace]; } else if (containsHTML == NO) { if (isTitle) { @@ -297,8 +298,12 @@ - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL } else { [attributedString addAttribute:NSFontAttributeName value:defaultFont range:NSMakeRange(0, attributedString.length)]; } + + } else { + [attributedString trimWhiteSpace]; } - return [self cleanStringForExtraLine:attributedString]; + + return attributedString; } - (BOOL)containsHTML:(NSString *)value { @@ -307,23 +312,6 @@ - (BOOL)containsHTML:(NSString *)value { return [htmlText evaluateWithObject:value]; } -/* - Cleaning required as HTML parser sometimes add extra newLine at the end of parsed string, - Title, Subtitle has single line restriction from apple - Desc can have mulitple lines - So even if remove newLine from title and subtitle, It won't affect UI - */ - -- (NSAttributedString *)cleanStringForExtraLine:(NSMutableAttributedString *)attributedString { - NSMutableAttributedString *mutableAttributedString = attributedString; - NSString *currentString = attributedString.string; - if ([currentString hasSuffix:@"\n"]) { - currentString = [currentString substringToIndex:[currentString length]-1]; - } - [mutableAttributedString.mutableString setString:currentString]; - return mutableAttributedString;; -} - #endif @end From d543d3e8884ebed1dd118d2fa057212788fb112d Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Fri, 28 Jan 2022 10:47:20 +0530 Subject: [PATCH 14/28] Dark mode support added using colour category --- .../WEGExtensionApp.xcodeproj/project.pbxproj | 4 ++ .../NSMutableAttributedString+Additions.h | 1 - .../ContentExtension/UIColor+DarkMode.h | 22 +++++++ .../ContentExtension/UIColor+DarkMode.m | 63 +++++++++++++++++++ ...EXCarouselPushNotificationViewController.m | 19 +++--- .../WEXRatingPushNotificationViewController.m | 44 +++++-------- ...chPushNotificationViewController+Private.h | 2 - .../WEXRichPushNotificationViewController.m | 18 ------ 8 files changed, 114 insertions(+), 59 deletions(-) create mode 100644 WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.h create mode 100644 WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.m diff --git a/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj b/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj index af90eb5..da98eaf 100644 --- a/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj +++ b/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj @@ -62,6 +62,8 @@ 56A49FB8EB9E003121E4C723 /* Pods-WEGExtensionApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WEGExtensionApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WEGExtensionApp/Pods-WEGExtensionApp.debug.xcconfig"; sourceTree = ""; }; 8167C6E259A361F9B2183151 /* libPods-WEGExtensionApp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WEGExtensionApp.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 8288374F4CC9F6A69DC1929F /* Pods-ContentExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ContentExtension/Pods-ContentExtension.debug.xcconfig"; sourceTree = ""; }; + A67089DF27A019E200DF27AC /* UIColor+DarkMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIColor+DarkMode.h"; sourceTree = ""; }; + A67089E027A019EF00DF27AC /* UIColor+DarkMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIColor+DarkMode.m"; sourceTree = ""; }; A6DDEE99279A7A8D007FADE1 /* NSMutableAttributedString+Additions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableAttributedString+Additions.h"; sourceTree = ""; }; A6DDEE9A279A7B22007FADE1 /* NSMutableAttributedString+Additions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableAttributedString+Additions.m"; sourceTree = ""; }; B554331A99838E3647290F86 /* Pods-ServiceExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ServiceExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ServiceExtension/Pods-ServiceExtension.debug.xcconfig"; sourceTree = ""; }; @@ -269,6 +271,8 @@ EC9A3DB521B6B15300C63B7D /* WEXRichPushNotificationViewController+Private.h */, A6DDEE99279A7A8D007FADE1 /* NSMutableAttributedString+Additions.h */, A6DDEE9A279A7B22007FADE1 /* NSMutableAttributedString+Additions.m */, + A67089DF27A019E200DF27AC /* UIColor+DarkMode.h */, + A67089E027A019EF00DF27AC /* UIColor+DarkMode.m */, ); path = ContentExtension; sourceTree = ""; diff --git a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h index 7552e96..6f0addd 100644 --- a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h +++ b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h @@ -7,7 +7,6 @@ #import - @interface NSMutableAttributedString (Additions) - (void)setFontFaceWithFont:(UIFont *)font; diff --git a/WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.h b/WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.h new file mode 100644 index 0000000..551427d --- /dev/null +++ b/WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.h @@ -0,0 +1,22 @@ +// +// UIColor+DarkMode.h +// WebEngage +// +// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved. +// + +#import + +@interface UIColor (DarkMode) + ++ (UIColor *)WEXWhiteColor; + ++ (UIColor *)WEXGreyColor; + ++ (UIColor *)WEXLabelColor; + ++ (UIColor *)WEXLightTextColor; + ++ (UIColor *)colorFromHexString:(NSString *)hexString defaultColor:(UIColor *)defaultColor; + +@end diff --git a/WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.m b/WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.m new file mode 100644 index 0000000..2859dec --- /dev/null +++ b/WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.m @@ -0,0 +1,63 @@ +// +// UIColor+DarkMode.m +// WebEngage +// +// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved. +// + +#import +#import "UIColor+DarkMode.h" + +@implementation UIColor (DarkMode) + ++ (UIColor *)WEXWhiteColor { + if (@available(iOS 13.0, *)) { + return UIColor.systemBackgroundColor; + } else { + return UIColor.whiteColor; + } +} + ++ (UIColor *)WEXGreyColor { + if (@available(iOS 13.0, *)) { + return UIColor.systemGrayColor; + } else { + return UIColor.lightGrayColor; + } +} + ++ (UIColor *)WEXLabelColor { + if (@available(iOS 13.0, *)) { + return UIColor.labelColor; + } else { + return UIColor.blackColor; + } +} + ++ (UIColor *)WEXLightTextColor { + if (@available(iOS 13.0, *)) { + return UIColor.systemGray4Color; + } else { + return UIColor.lightTextColor; + } +} + ++ (UIColor *)colorFromHexString:(NSString *)hexString defaultColor:(UIColor *)defaultColor { + if (hexString == (id)[NSNull null] || hexString.length == 0) { + return defaultColor; + } + + unsigned rgbValue = 0; + NSScanner *scanner = [NSScanner scannerWithString:hexString]; + + if ([hexString hasPrefix:@"#"]) { + [scanner setScanLocation:1]; // bypass '#' character + } else { + [scanner setScanLocation:0]; + } + + [scanner scanHexInt:&rgbValue]; + return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; +} + +@end diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index fd9eff6..721d6f4 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -8,6 +8,7 @@ #import "WEXCarouselPushNotificationViewController.h" #import "WEXRichPushNotificationViewController+Private.h" +#import "UIColor+DarkMode.h" #define CONTENT_PADDING 10 #define TITLE_BODY_SPACE 5 @@ -243,8 +244,8 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA float superViewHeight = viewHeight + 2 * verticalMargins; NSString *colorHex = notification.request.content.userInfo[@"expandableDetails"][@"bckColor"]; - self.view.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; - self.viewController.view.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; + self.view.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXWhiteColor]; + self.viewController.view.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXWhiteColor]; NSString *mode = notification.request.content.userInfo[@"expandableDetails"][@"mode"]; @@ -289,10 +290,10 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA } UIView *topSeparator = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, superViewWidth, 0.5)]; - topSeparator.backgroundColor = [UIColor lightGrayColor]; + topSeparator.backgroundColor = [UIColor WEXGreyColor]; UIView *bottomSeparator = [[UIView alloc] initWithFrame:CGRectMake(0.0, superViewHeight - 0.5, superViewWidth, 0.5)]; - bottomSeparator.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.lightGrayColor]; + bottomSeparator.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXGreyColor]; NSDictionary *extensionAttributes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSExtension"][@"NSExtensionAttributes"]; @@ -323,7 +324,7 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA // Add a notification content view for displaying title and body. UIView *notificationContentView = [[UIView alloc] init]; - notificationContentView.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; + notificationContentView.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXWhiteColor]; UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES]; @@ -659,7 +660,7 @@ - (UIView *)viewAtPosition:(NSInteger)index { UIView *viewContainer = viewToReturn; UIImage *image = self.images[index]; - viewContainer.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.lightGrayColor]; + viewContainer.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXGreyColor]; UIImageView *imageView = self.imageViews[cachedViewIndex]; imageView.frame = CGRectMake(0.0, 0.0, viewWidth, viewHeight); @@ -677,7 +678,7 @@ - (UIView *)viewAtPosition:(NSInteger)index { viewWidth, descriptionViewHeight); descriptionView.alpha = DESCRIPTION_VIEW_ALPHA; - descriptionView.backgroundColor = [UIColor whiteColor]; + descriptionView.backgroundColor = [UIColor WEXWhiteColor]; UILabel *descriptionLabel = self.descriptionLabels[cachedViewIndex]; descriptionLabel.frame = @@ -686,7 +687,7 @@ - (UIView *)viewAtPosition:(NSInteger)index { descriptionLabel.text = carouselItem[@"actionText"]; descriptionLabel.textAlignment = NSTextAlignmentCenter; - descriptionLabel.textColor = [UIColor blackColor]; + descriptionLabel.textColor = [UIColor WEXLabelColor]; [descriptionView addSubview:descriptionLabel]; @@ -701,7 +702,7 @@ - (UIView *)viewAtPosition:(NSInteger)index { UIView *alphaView = self.alphaViews[cachedViewIndex]; alphaView.frame = CGRectMake(0.0, 0.0, viewWidth, viewHeight); alphaView.alpha = 0.0; - alphaView.backgroundColor = [UIColor whiteColor]; + alphaView.backgroundColor = [UIColor WEXWhiteColor]; [viewContainer addSubview:alphaView]; } diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index fd04280..b1bc589 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -7,6 +7,7 @@ #import "WEXRatingPushNotificationViewController.h" +#import "UIColor+DarkMode.h" //#define NO_OF_STARS 5 #define STAR_BAR_HEIGHT 50 @@ -120,7 +121,7 @@ @implementation WEXRatingPushNotificationViewController - (void)initialiseViewHierarchy { - self.view.backgroundColor = [UIColor yellowColor]; + self.view.backgroundColor = [UIColor WEXWhiteColor]; UIView *superViewWrapper = [[UIView alloc] init]; @@ -179,13 +180,11 @@ - (void)initialiseViewHierarchy { textDisplayView.opaque = NO; textDisplayView.backgroundColor = [UIColor clearColor]; } else { - if (bckColor) { - textDisplayView.backgroundColor = [self colorWithHexString:bckColor]; + textDisplayView.backgroundColor = [UIColor colorFromHexString:bckColor defaultColor:UIColor.WEXLightTextColor]; } else { - textDisplayView.backgroundColor = [UIColor lightTextColor]; + textDisplayView.backgroundColor = UIColor.WEXLightTextColor; } - } UILabel *titleLabel; @@ -206,9 +205,9 @@ - (void)initialiseViewHierarchy { titleLabel.text = title; titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; if (textColor) { - titleLabel.textColor = [self colorWithHexString:textColor]; + titleLabel.textColor = [UIColor colorFromHexString:bckColor defaultColor:UIColor.WEXLabelColor]; } else { - titleLabel.textColor = [UIColor blackColor]; + titleLabel.textColor = UIColor.WEXLabelColor; } [textDisplayView addSubview:titleLabel]; @@ -220,9 +219,9 @@ - (void)initialiseViewHierarchy { messageLabel.text = message; if (textColor) { - messageLabel.textColor = [self colorWithHexString:textColor]; + messageLabel.textColor = [UIColor colorFromHexString:bckColor defaultColor:UIColor.WEXLabelColor]; } else { - messageLabel.textColor = [UIColor blackColor]; + messageLabel.textColor = UIColor.WEXLabelColor; } messageLabel.numberOfLines = 3; @@ -235,7 +234,7 @@ - (void)initialiseViewHierarchy { //TODO: Add conditions for lack of rich texts UIView *contentSeparator = [[UIView alloc] init]; - contentSeparator.backgroundColor = [UIColor lightGrayColor]; + contentSeparator.backgroundColor = UIColor.WEXGreyColor; [superViewWrapper addSubview:contentSeparator]; @@ -261,7 +260,7 @@ - (void)initialiseViewHierarchy { // Add a notification content view for displaying title and body. UIView *richContentView = [[UIView alloc] init]; - richContentView.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; + richContentView.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXWhiteColor]; UILabel *richTitleLabel = [[UILabel alloc] init]; richTitleLabel.attributedText = [self.viewController getHtmlParsedString:richTitle isTitle:YES]; @@ -283,12 +282,12 @@ - (void)initialiseViewHierarchy { [superViewWrapper addSubview:richContentView]; UIView *separator = [[UIView alloc] init]; - separator.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.lightGrayColor]; + separator.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXGreyColor]; [superViewWrapper addSubview:separator]; UIView *starRatingView = [[UIView alloc] init]; - starRatingView.backgroundColor = [self.viewController colorFromHexString:colorHex defaultColor:UIColor.whiteColor]; + starRatingView.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXWhiteColor]; self.labelsWrapper = [[UIView alloc] init]; self.unselectedLabel = [[UILabel alloc] init]; @@ -354,7 +353,7 @@ - (void)renderStarControl { self.unselectedLabel.text = starStringUnselected; - self.unselectedLabel.textColor = [UIColor lightGrayColor]; + self.unselectedLabel.textColor = UIColor.WEXGreyColor; self.unselectedLabel.font = [self.unselectedLabel.font fontWithSize:STAR_FONT_SIZE]; } @@ -551,7 +550,7 @@ - (UIView *)inputAccessoryView { CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, 50); UIView *inputAccessoryView = [[UIView alloc] initWithFrame:frame]; - inputAccessoryView.backgroundColor = [UIColor lightTextColor]; + inputAccessoryView.backgroundColor = UIColor.WEXLightTextColor; UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeSystem]; NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:@"Done" @@ -559,7 +558,7 @@ - (UIView *)inputAccessoryView { NSUnderlineStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleNone], NSFontAttributeName: [UIFont boldSystemFontOfSize:20], - NSForegroundColorAttributeName: [self colorWithHexString:@"0077cc"] + NSForegroundColorAttributeName: [UIColor colorFromHexString:@"0077cc" defaultColor:UIColor.blueColor] }]; [doneButton setAttributedTitle:attrTitle forState:UIControlStateNormal]; @@ -676,19 +675,6 @@ - (void)didReceiveNotificationResponse:(UNNotificationResponse *)response comple } } -- (UIColor *)colorWithHexString:(NSString *)hexString { - - unsigned rgbValue = 0; - NSScanner *scanner = [NSScanner scannerWithString:hexString]; - [scanner setScanLocation:1]; // bypass '#' character - [scanner scanHexInt:&rgbValue]; - - return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 - green:((rgbValue & 0xFF00) >> 8)/255.0 - blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; -} - - #endif @end diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h index ec92c59..0b6526d 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h @@ -26,8 +26,6 @@ - (NSTextAlignment)naturalTextAligmentForText:(NSString*) text; -- (UIColor *)colorFromHexString:(NSString *)hexString defaultColor:(UIColor *)defaultColor; - - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL)isTitle; #endif diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index 77e0cb6..1156fe9 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -246,24 +246,6 @@ - (NSTextAlignment)naturalTextAligmentForText:(NSString*)text { } } -- (UIColor *)colorFromHexString:(NSString *)hexString defaultColor:(UIColor *)defaultColor { - if (hexString == (id)[NSNull null] || hexString.length == 0) { - return defaultColor; - } - - unsigned rgbValue = 0; - NSScanner *scanner = [NSScanner scannerWithString:hexString]; - - if ([hexString hasPrefix:@"#"]) { - [scanner setScanLocation:1]; // bypass '#' character - } else { - [scanner setScanLocation:0]; - } - - [scanner scanHexInt:&rgbValue]; - return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; -} - - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL)isTitle { NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData: [textString dataUsingEncoding:NSUnicodeStringEncoding] From 433b59eb953324774058a08fe6c7f585ef747add Mon Sep 17 00:00:00 2001 From: Bhavesh Sarwar <> Date: Fri, 28 Jan 2022 16:01:18 +0530 Subject: [PATCH 15/28] - Banner Category manipulation added --- .../WEXBannerPushNotificationViewController.m | 51 +++++++++++++++++++ .../WEXPushNotificationService.m | 46 ++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m index bb804f9..50a1f6f 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -29,10 +29,61 @@ @implementation WEXBannerPushNotificationViewController #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 +- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion{ + completion(UNNotificationContentExtensionResponseOptionDismissAndForwardAction); +} + - (void)didReceiveNotification:(UNNotification *)notification API_AVAILABLE(ios(10.0)) { + self.notification = notification; +// NSDictionary *userInfo = notification.request.content.userInfo; +// NSString *catName = [userInfo valueForKeyPath:@"expandableDetails.category"]; +// UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; +// NSString *bannerCatName = @"WEG_BANNER_V1"; +// [center getNotificationCategoriesWithCompletionHandler:^(NSSet *existingCategories) { +// UNNotificationCategory * defaultCategory ; +// NSMutableSet * existingMutablecat = [[NSMutableSet alloc] init]; +// for(UNNotificationCategory *dic in existingCategories){ +// if([dic.identifier isEqual: catName]){ +// defaultCategory = dic; +// } +// if(![dic.identifier isEqual: bannerCatName]){ +// [existingMutablecat addObject:dic]; +// } +// } +// +// +// NSMutableArray *actions = [NSMutableArray arrayWithCapacity:defaultCategory.actions.count]; +// +// for (UNNotificationAction *action in defaultCategory.actions) { +// UNNotificationAction *actionObject = [UNNotificationAction actionWithIdentifier:action.identifier +// title:action.title +// options:action.options]; +// [actions addObject:actionObject]; +// } +// +// UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:bannerCatName +// actions:actions +// intentIdentifiers:@[] +// options:UNNotificationCategoryOptionCustomDismissAction]; +// +// +// [existingMutablecat addObject:category]; +// [center setNotificationCategories:existingMutablecat]; +//// use +// +// +// +//// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ +////// NSLog(@"parameter1: %d parameter2: %f", parameter1, parameter2); +//// [self drawBannerViewWith:expandableDetails[@"image"]]; +//// }); +// +// }]; [self initialiseViewHierarchy]; + + } - (void)initialiseViewHierarchy { diff --git a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m index aead9de..d90c286 100644 --- a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m +++ b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m @@ -51,8 +51,50 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request } else if (expandableDetails && style && ([style isEqualToString:@"RATING_V1"] || [style isEqualToString:@"BIG_PICTURE"])) { - - [self drawBannerViewWith:expandableDetails[@"image"]]; + if ([style isEqualToString:@"BIG_PICTURE"]){ + NSString *bannerCatName = @"WEG_BANNER_V1"; + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + [center getNotificationCategoriesWithCompletionHandler:^(NSSet *existingCategories) { + UNNotificationCategory * defaultCategory ; + NSMutableSet * existingMutablecat = [[NSMutableSet alloc] init]; + for(UNNotificationCategory *dic in existingCategories){ + if([dic.identifier isEqual: self.bestAttemptContent.categoryIdentifier]){ + defaultCategory = dic; + } + if(![dic.identifier isEqual: bannerCatName]){ + [existingMutablecat addObject:dic]; + } + } + + + NSMutableArray *actions = [NSMutableArray arrayWithCapacity:defaultCategory.actions.count]; + + for (UNNotificationAction *action in defaultCategory.actions) { + UNNotificationAction *actionObject = [UNNotificationAction actionWithIdentifier:action.identifier + title:action.title + options:action.options]; + [actions addObject:actionObject]; + } + + UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:bannerCatName + actions:actions + intentIdentifiers:@[] + options:UNNotificationCategoryOptionCustomDismissAction]; + + + [existingMutablecat addObject:category]; + [center setNotificationCategories:existingMutablecat]; + [self.bestAttemptContent setCategoryIdentifier:bannerCatName]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ +// NSLog(@"parameter1: %d parameter2: %f", parameter1, parameter2); + [self drawBannerViewWith:expandableDetails[@"image"]]; + }); + + }]; + }else{ + [self drawBannerViewWith:expandableDetails[@"image"]]; + } +// [self drawBannerViewWith:expandableDetails[@"image"]]; } else { [self trackEventWithCompletion:^{ From d490f62de667aa23a5c4d731105b86fb4738a946 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Fri, 28 Jan 2022 22:52:59 +0530 Subject: [PATCH 16/28] Banner modified --- Extension App/ContentExtension/Info.plist | 1 - .../WEGExtensionApp/AppDelegate.swift | 8 - .../WEXBannerPushNotificationViewController.m | 84 +--------- ...EXCarouselPushNotificationViewController.m | 1 - .../WEXRatingPushNotificationViewController.m | 2 +- .../WEXPushNotificationService.m | 143 ++++++------------ 6 files changed, 56 insertions(+), 183 deletions(-) diff --git a/Extension App/ContentExtension/Info.plist b/Extension App/ContentExtension/Info.plist index 3ea36e4..94e3301 100644 --- a/Extension App/ContentExtension/Info.plist +++ b/Extension App/ContentExtension/Info.plist @@ -30,7 +30,6 @@ WEG_CAROUSEL_V1 WEG_RATING_V1 - BIG_PICTURE UNNotificationExtensionInitialContentSizeRatio 1 diff --git a/Extension App/WEGExtensionApp/AppDelegate.swift b/Extension App/WEGExtensionApp/AppDelegate.swift index 29879db..0c3a085 100644 --- a/Extension App/WEGExtensionApp/AppDelegate.swift +++ b/Extension App/WEGExtensionApp/AppDelegate.swift @@ -16,16 +16,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - -// addCustomPushCategory() - WebEngage.sharedInstance()?.application(application, didFinishLaunchingWithOptions: launchOptions, autoRegister: true) WebEngage.sharedInstance().user.login("ExtensionQWE1") return true } - - private func addCustomPushCategory() { - let category = UNNotificationCategory.init(identifier: "BIG_PICTURE", actions: [], intentIdentifiers: [], options: []) - UNUserNotificationCenter.current().setNotificationCategories([category]) - } } diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m index 50a1f6f..223e28f 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -7,6 +7,7 @@ #import "WEXBannerPushNotificationViewController.h" #import "WEXRichPushNotificationViewController+Private.h" +#import "UIColor+DarkMode.h" #define CONTENT_PADDING 10 #define TITLE_BODY_SPACE 5 @@ -29,65 +30,13 @@ @implementation WEXBannerPushNotificationViewController #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 -- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion{ - completion(UNNotificationContentExtensionResponseOptionDismissAndForwardAction); -} - - (void)didReceiveNotification:(UNNotification *)notification API_AVAILABLE(ios(10.0)) { - self.notification = notification; - -// NSDictionary *userInfo = notification.request.content.userInfo; -// NSString *catName = [userInfo valueForKeyPath:@"expandableDetails.category"]; -// UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; -// NSString *bannerCatName = @"WEG_BANNER_V1"; -// [center getNotificationCategoriesWithCompletionHandler:^(NSSet *existingCategories) { -// UNNotificationCategory * defaultCategory ; -// NSMutableSet * existingMutablecat = [[NSMutableSet alloc] init]; -// for(UNNotificationCategory *dic in existingCategories){ -// if([dic.identifier isEqual: catName]){ -// defaultCategory = dic; -// } -// if(![dic.identifier isEqual: bannerCatName]){ -// [existingMutablecat addObject:dic]; -// } -// } -// -// -// NSMutableArray *actions = [NSMutableArray arrayWithCapacity:defaultCategory.actions.count]; -// -// for (UNNotificationAction *action in defaultCategory.actions) { -// UNNotificationAction *actionObject = [UNNotificationAction actionWithIdentifier:action.identifier -// title:action.title -// options:action.options]; -// [actions addObject:actionObject]; -// } -// -// UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:bannerCatName -// actions:actions -// intentIdentifiers:@[] -// options:UNNotificationCategoryOptionCustomDismissAction]; -// -// -// [existingMutablecat addObject:category]; -// [center setNotificationCategories:existingMutablecat]; -//// use -// -// -// -//// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ -////// NSLog(@"parameter1: %d parameter2: %f", parameter1, parameter2); -//// [self drawBannerViewWith:expandableDetails[@"image"]]; -//// }); -// -// }]; [self initialiseViewHierarchy]; - - } - (void)initialiseViewHierarchy { - self.view.backgroundColor = [UIColor whiteColor]; + self.view.backgroundColor = [UIColor WEXWhiteColor]; UIView *superViewWrapper = [[UIView alloc] init]; [self.view addSubview:superViewWrapper]; @@ -134,9 +83,10 @@ - (void)setupBannerImageView { - (void)setupLabelsContainer { UIView *superViewWrapper = self.view.subviews[0]; + NSString *colorHex = self.notification.request.content.userInfo[@"expandableDetails"][@"bckColor"]; UIView *richContentView = [[UIView alloc] init]; - richContentView.backgroundColor = [UIColor whiteColor]; + richContentView.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXWhiteColor]; NSDictionary *expandedDetails = self.notification.request.content.userInfo[@"expandableDetails"]; NSString *title = expandedDetails[@"rt"]; @@ -158,38 +108,18 @@ - (void)setupLabelsContainer { } UILabel *richTitleLabel = [[UILabel alloc] init]; - NSAttributedString *attributedTitle = [[NSMutableAttributedString alloc] - initWithData: [title dataUsingEncoding:NSUnicodeStringEncoding] - options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } - documentAttributes: nil - error: nil - ]; + richTitleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; - richTitleLabel.attributedText = attributedTitle; - richTitleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; UILabel *richSubLabel = [[UILabel alloc] init]; - NSAttributedString *attributedSubTitle = [[NSMutableAttributedString alloc] - initWithData: [subtitle dataUsingEncoding:NSUnicodeStringEncoding] - options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } - documentAttributes: nil - error: nil - ]; + richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; - richSubLabel.attributedText = attributedSubTitle; - richSubLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; UILabel *richBodyLabel = [[UILabel alloc] init]; - NSAttributedString *attributedBody = [[NSMutableAttributedString alloc] - initWithData: [message dataUsingEncoding:NSUnicodeStringEncoding] - options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } - documentAttributes: nil - error: nil - ]; + richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; richBodyLabel.numberOfLines = 0; richBodyLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; - richBodyLabel.attributedText = attributedBody; [richContentView addSubview:richTitleLabel]; [richContentView addSubview:richSubLabel]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index ab0a36e..721d6f4 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -338,7 +338,6 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA bodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; bodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:bodyLabel.text]; bodyLabel.numberOfLines = 0; - bodyLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; [notificationContentView addSubview:titleLabel]; [notificationContentView addSubview:subTitleLabel]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index c75c353..66a96d9 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -274,7 +274,7 @@ - (void)initialiseViewHierarchy { richBodyLabel.attributedText = [self.viewController getHtmlParsedString:richMessage isTitle:NO]; richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; richBodyLabel.numberOfLines = 0; - richBodyLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; + [richContentView addSubview:richTitleLabel]; [richContentView addSubview:richSubLabel]; diff --git a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m index d90c286..b7c3eda 100644 --- a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m +++ b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m @@ -32,11 +32,9 @@ @implementation WEXPushNotificationService - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler { -// [self setCustomCategory]; - self.contentHandler = contentHandler; self.bestAttemptContent = [request.content mutableCopy]; - + [self setExtensionDefaults]; NSLog(@"Push Notification content: %@", request.content.userInfo); @@ -46,57 +44,13 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request NSString *style = expandableDetails[@"style"]; if (expandableDetails && style && [style isEqualToString:@"CAROUSEL_V1"]) { - [self drawCarouselViewWith:expandableDetails[@"items"]]; - } - else if (expandableDetails && style && - ([style isEqualToString:@"RATING_V1"] || [style isEqualToString:@"BIG_PICTURE"])) { - if ([style isEqualToString:@"BIG_PICTURE"]){ - NSString *bannerCatName = @"WEG_BANNER_V1"; - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - [center getNotificationCategoriesWithCompletionHandler:^(NSSet *existingCategories) { - UNNotificationCategory * defaultCategory ; - NSMutableSet * existingMutablecat = [[NSMutableSet alloc] init]; - for(UNNotificationCategory *dic in existingCategories){ - if([dic.identifier isEqual: self.bestAttemptContent.categoryIdentifier]){ - defaultCategory = dic; - } - if(![dic.identifier isEqual: bannerCatName]){ - [existingMutablecat addObject:dic]; - } - } - - - NSMutableArray *actions = [NSMutableArray arrayWithCapacity:defaultCategory.actions.count]; - - for (UNNotificationAction *action in defaultCategory.actions) { - UNNotificationAction *actionObject = [UNNotificationAction actionWithIdentifier:action.identifier - title:action.title - options:action.options]; - [actions addObject:actionObject]; - } - - UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:bannerCatName - actions:actions - intentIdentifiers:@[] - options:UNNotificationCategoryOptionCustomDismissAction]; - - - [existingMutablecat addObject:category]; - [center setNotificationCategories:existingMutablecat]; - [self.bestAttemptContent setCategoryIdentifier:bannerCatName]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ -// NSLog(@"parameter1: %d parameter2: %f", parameter1, parameter2); - [self drawBannerViewWith:expandableDetails[@"image"]]; - }); - - }]; - }else{ - [self drawBannerViewWith:expandableDetails[@"image"]]; - } -// [self drawBannerViewWith:expandableDetails[@"image"]]; - } - else { + + } else if (expandableDetails && style && + ([style isEqualToString:@"RATING_V1"] || [style isEqualToString:@"BIG_PICTURE"])) { + [self drawBannerViewWith:expandableDetails[@"image"]]; + + } else { [self trackEventWithCompletion:^{ self.contentHandler(self.bestAttemptContent); }]; @@ -156,23 +110,23 @@ - (void)drawCarouselViewWith:(NSArray *)items { [self fetchAttachmentFor:imageURL at:itemCounter completionHandler:^(UNNotificationAttachment *attachment, NSUInteger index) { - - imageDownloadAttemptCounter++; - - if (attachment) { - NSLog(@"Downloaded Attachment No. %ld", (unsigned long)index); - [attachmentsArray addObject:attachment]; - self.bestAttemptContent.attachments = attachmentsArray; - } - - if (imageDownloadAttemptCounter == items.count) { - - [self trackEventWithCompletion:^{ - NSLog(@"Ending WebEngage Rich Push Service"); - self.contentHandler(self.bestAttemptContent); - }]; - } - }]; + + imageDownloadAttemptCounter++; + + if (attachment) { + NSLog(@"Downloaded Attachment No. %ld", (unsigned long)index); + [attachmentsArray addObject:attachment]; + self.bestAttemptContent.attachments = attachmentsArray; + } + + if (imageDownloadAttemptCounter == items.count) { + + [self trackEventWithCompletion:^{ + NSLog(@"Ending WebEngage Rich Push Service"); + self.contentHandler(self.bestAttemptContent); + }]; + } + }]; itemCounter++; } } @@ -183,16 +137,16 @@ - (void)drawBannerViewWith:(NSString *)urlStr { [self fetchAttachmentFor:urlStr at:0 completionHandler:^(UNNotificationAttachment *attachment, NSUInteger index) { - - if (attachment) { - NSLog(@"WebEngage Downloaded Image for Rating Layout"); - self.bestAttemptContent.attachments = @[ attachment ]; - } - - [self trackEventWithCompletion:^{ - self.contentHandler(self.bestAttemptContent); - }]; - }]; + + if (attachment) { + NSLog(@"WebEngage Downloaded Image for Rating Layout"); + self.bestAttemptContent.attachments = @[ attachment ]; + } + + [self trackEventWithCompletion:^{ + self.contentHandler(self.bestAttemptContent); + }]; + }]; } - (void)fetchAttachmentFor:(NSString *)urlString @@ -264,7 +218,7 @@ - (void)trackEventWithCompletion:(void(^)(void))completion { else { NSLog(@"Push Tracker URLResponse: %@", response); } - + if (completion) { completion(); } @@ -326,21 +280,20 @@ - (NSData *)getTrackerRequestBody { // Passing custom data into event tracking id customData = self.bestAttemptContent.userInfo[@"customData"]; - + if (customData && [customData isKindOfClass:[NSArray class]]) { - - NSArray *customDataArray = (NSArray *)customData; - - NSMutableDictionary *customDataDictionary = [[NSMutableDictionary alloc] - initWithCapacity:customDataArray.count]; - - for (NSDictionary *customDataItem in customDataArray) { - if (customDataItem[@"key"] && [customDataItem[@"key"] isKindOfClass:[NSString class]]) { - customDataDictionary[customDataItem[@"key"]] = - customDataItem[@"value"]; - } - } - + NSArray *customDataArray = (NSArray *)customData; + + NSMutableDictionary *customDataDictionary = [[NSMutableDictionary alloc] + initWithCapacity:customDataArray.count]; + + for (NSDictionary *customDataItem in customDataArray) { + if (customDataItem[@"key"] && [customDataItem[@"key"] isKindOfClass:[NSString class]]) { + customDataDictionary[customDataItem[@"key"]] = + customDataItem[@"value"]; + } + } + body[@"event_data"] = customDataDictionary; } else { body[@"event_data"] = @{}; From 5f801bccd8fa5cb7ce9569b1739229f99b7e45dd Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Wed, 2 Feb 2022 01:18:00 +0530 Subject: [PATCH 17/28] Notification service updated to include Banner layout changes --- Extension App/ContentExtension/Info.plist | 8 ++ .../WEXBannerPushNotificationViewController.m | 19 +++- .../WEXPushNotificationService.m | 97 +++++++++++++++---- 3 files changed, 102 insertions(+), 22 deletions(-) diff --git a/Extension App/ContentExtension/Info.plist b/Extension App/ContentExtension/Info.plist index 94e3301..6a6feba 100644 --- a/Extension App/ContentExtension/Info.plist +++ b/Extension App/ContentExtension/Info.plist @@ -30,6 +30,14 @@ WEG_CAROUSEL_V1 WEG_RATING_V1 + WEG_BANNER_V1 + WEG_BANNER_V2 + WEG_BANNER_V3 + WEG_BANNER_V4 + WEG_BANNER_V5 + WEG_BANNER_V6 + WEG_BANNER_V7 + WEG_BANNER_V8 UNNotificationExtensionInitialContentSizeRatio 1 diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m index 223e28f..01a5460 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -35,6 +35,10 @@ - (void)didReceiveNotification:(UNNotification *)notification API_AVAILABLE(ios( [self initialiseViewHierarchy]; } +- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion{ + completion(UNNotificationContentExtensionResponseOptionDismissAndForwardAction); +} + - (void)initialiseViewHierarchy { self.view.backgroundColor = [UIColor WEXWhiteColor]; @@ -53,6 +57,7 @@ - (void)setupBannerImageView { NSDictionary *expandableDetails = self.notification.request.content.userInfo[@"expandableDetails"]; + UIImageView *imageView = [[UIImageView alloc] init]; if (expandableDetails[@"image"]) { if (self.notification.request.content.attachments && self.notification.request.content.attachments.count > 0) { @@ -67,17 +72,23 @@ - (void)setupBannerImageView { [attachment.URL stopAccessingSecurityScopedResource]; if (image) { - UIImageView *imageView = [[UIImageView alloc] init]; imageView.image = image; - imageView.contentMode = UIViewContentModeScaleAspectFill; - [mainContentView addSubview:imageView]; + } else { + NSLog(@"Image not present in cache!"); } } } else { NSLog(@"Expected to be running iOS version 10 or above"); } + } else { + NSLog(@"Attachment not present for: %@", expandableDetails[@"image"]); } + } else { + NSLog(@"Image not present in payload: %@", expandableDetails[@"image"]); } + + imageView.contentMode = UIViewContentModeScaleAspectFill; + [mainContentView addSubview:imageView]; [self setupLabelsContainer]; } @@ -163,6 +174,8 @@ - (void)setupConstraints { CGFloat imageAspect = LANDSCAPE_ASPECT; if (bannerImage && bannerImage.size.height != 0) { imageAspect = bannerImage.size.height/bannerImage.size.width; + } else { + imageAspect = 0; } [imageView.topAnchor constraintEqualToAnchor:mainContentView.topAnchor].active = YES; diff --git a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m index b7c3eda..9c11479 100644 --- a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m +++ b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m @@ -17,6 +17,7 @@ @interface WEXPushNotificationService () @property (nonatomic) UNMutableNotificationContent *bestAttemptContent; @property (nonatomic) NSString *enviroment; @property NSDictionary *sharedUserDefaults; +@property NSArray *bannerCategories; #endif @end @@ -35,6 +36,7 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request self.contentHandler = contentHandler; self.bestAttemptContent = [request.content mutableCopy]; + self.bannerCategories = @[@"WEG_BANNER_V1", @"WEG_BANNER_V2", @"WEG_BANNER_V3", @"WEG_BANNER_V4", @"WEG_BANNER_V5", @"WEG_BANNER_V6", @"WEG_BANNER_V7", @"WEG_BANNER_V8"]; [self setExtensionDefaults]; NSLog(@"Push Notification content: %@", request.content.userInfo); @@ -46,9 +48,64 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request if (expandableDetails && style && [style isEqualToString:@"CAROUSEL_V1"]) { [self drawCarouselViewWith:expandableDetails[@"items"]]; - } else if (expandableDetails && style && - ([style isEqualToString:@"RATING_V1"] || [style isEqualToString:@"BIG_PICTURE"])) { + } else if (expandableDetails && style && [style isEqualToString:@"RATING_V1"]) { [self drawBannerViewWith:expandableDetails[@"image"]]; + + } else if (expandableDetails && style && [style isEqualToString:@"BIG_PICTURE"]) { + NSString *bannerCatName = [self getBannerCategoryFor:self.bestAttemptContent.categoryIdentifier]; + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + + [center getNotificationCategoriesWithCompletionHandler:^(NSSet *existingCategories) { + UNNotificationCategory *currentCategory; + BOOL isBannerRegistered = NO; + BOOL isCurrentCatBanner = NO; + NSMutableSet *existingMutablecat = [[NSMutableSet alloc] init]; + + for(UNNotificationCategory *dict in existingCategories) { + if([dict.identifier isEqual: self.bestAttemptContent.categoryIdentifier]) { + currentCategory = dict; + isBannerRegistered = [dict.identifier isEqualToString:bannerCatName]; + isCurrentCatBanner = [self.bannerCategories containsObject:dict.identifier]; + } else { + [existingMutablecat addObject:dict]; + } + } + + if (isBannerRegistered) { + if (!isCurrentCatBanner) { + [self.bestAttemptContent setCategoryIdentifier:bannerCatName]; + } + [self drawBannerViewWith:expandableDetails[@"image"]]; + return; + } + + // Register banner layout here. + NSMutableArray *actions = [NSMutableArray arrayWithCapacity:currentCategory.actions.count]; + + for (UNNotificationAction *action in currentCategory.actions) { + UNNotificationAction *actionObject = [UNNotificationAction actionWithIdentifier:action.identifier + title:action.title + options:action.options]; + [actions addObject:actionObject]; + } + + UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:bannerCatName + actions:actions + intentIdentifiers:@[] + options:UNNotificationCategoryOptionCustomDismissAction]; + [existingMutablecat addObject:category]; + [center setNotificationCategories:existingMutablecat]; + [self.bestAttemptContent setCategoryIdentifier:bannerCatName]; + /* + Dispatching on Main thread after 2 sec delay to make sure our category is registered with NotificationCenter + Registering will make sure, contentHandler will invoke ContentExtension with this custom category + + NOTE: Use this workaround till we receive banner category in network response. + */ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [self drawBannerViewWith:expandableDetails[@"image"]]; + }); + }]; } else { [self trackEventWithCompletion:^{ @@ -57,23 +114,26 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request } } -- (void)setCustomCategory { - UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"NEW" - actions:@[] - intentIdentifiers:@[] - options:UNNotificationCategoryOptionNone]; - NSMutableSet *categories = [NSMutableSet setWithCapacity:1]; - [categories addObject:category]; - - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; +// NOTE: This mapping is a temporary workaround, Will be removed in future releases + +- (NSString *)getBannerCategoryFor:(NSString *)currentCategory { + NSDictionary *bannerMapping = @{ + @"default" : self.bannerCategories[0], + @"18dfbbcc" : self.bannerCategories[1], + @"16589g0g" : self.bannerCategories[2], + @"15ead296" : self.bannerCategories[3], + @"17543720" : self.bannerCategories[4], + @"16e66ba8" : self.bannerCategories[5], + @"1c406g7a" : self.bannerCategories[6], + @"1bd2a2g0" : self.bannerCategories[7] + }; - [center getNotificationCategoriesWithCompletionHandler:^(NSSet *existingCategories) { - if (existingCategories && existingCategories.count > 0) { - [categories unionSet:existingCategories]; - } - - [center setNotificationCategories:categories]; - }]; + NSString *category = bannerMapping[currentCategory]; + if (category) { + return category; + } else { + return currentCategory; + } } - (void)setExtensionDefaults { @@ -99,7 +159,6 @@ - (void)drawCarouselViewWith:(NSArray *)items { NSMutableArray *attachmentsArray = [[NSMutableArray alloc] initWithCapacity:items.count]; if (items.count >= 3) { - NSUInteger itemCounter = 0; NSUInteger __block imageDownloadAttemptCounter = 0; From eb7c4874d164fb2cafb2a3cbceebee0607dcaae4 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Wed, 2 Feb 2022 13:59:19 +0530 Subject: [PATCH 18/28] Default category added to banner mapping --- .../Classes/NotificationService/WEXPushNotificationService.m | 1 + 1 file changed, 1 insertion(+) diff --git a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m index 9c11479..743a1d1 100644 --- a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m +++ b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m @@ -119,6 +119,7 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request - (NSString *)getBannerCategoryFor:(NSString *)currentCategory { NSDictionary *bannerMapping = @{ @"default" : self.bannerCategories[0], + @"19db52de" : self.bannerCategories[0], @"18dfbbcc" : self.bannerCategories[1], @"16589g0g" : self.bannerCategories[2], @"15ead296" : self.bannerCategories[3], From 82cd4964a40062027df4870e6036a3ed6155dfd1 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Thu, 17 Feb 2022 10:40:36 +0530 Subject: [PATCH 19/28] - Banner desc rich issue fixed - Rating default colour issue fixed --- .../WEXBannerPushNotificationViewController.m | 1 - .../WEXRatingPushNotificationViewController.m | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m index 01a5460..787441b 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -130,7 +130,6 @@ - (void)setupLabelsContainer { richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; richBodyLabel.numberOfLines = 0; - richBodyLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; [richContentView addSubview:richTitleLabel]; [richContentView addSubview:richSubLabel]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index 66a96d9..8ec94fd 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -205,7 +205,7 @@ - (void)initialiseViewHierarchy { titleLabel.text = title; titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; if (textColor) { - titleLabel.textColor = [UIColor colorFromHexString:bckColor defaultColor:UIColor.WEXLabelColor]; + titleLabel.textColor = [UIColor colorFromHexString:textColor defaultColor:UIColor.WEXLabelColor]; } else { titleLabel.textColor = UIColor.WEXLabelColor; } @@ -219,7 +219,7 @@ - (void)initialiseViewHierarchy { messageLabel.text = message; if (textColor) { - messageLabel.textColor = [UIColor colorFromHexString:bckColor defaultColor:UIColor.WEXLabelColor]; + messageLabel.textColor = [UIColor colorFromHexString:textColor defaultColor:UIColor.WEXLabelColor]; } else { messageLabel.textColor = UIColor.WEXLabelColor; } From b2e348bbb9229b3f7b333e6f33fcff2d4b87b443 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Fri, 18 Feb 2022 23:35:13 +0530 Subject: [PATCH 20/28] Text layout setup added --- Extension App/ContentExtension/Info.plist | 10 +- .../WEGExtensionApp.xcodeproj/project.pbxproj | 8 +- .../WEXBannerPushNotificationViewController.m | 2 - .../WEXRichPushNotificationViewController.m | 3 + .../WEXTextPushNotificationViewController.h | 24 +++ .../WEXTextPushNotificationViewController.m | 172 ++++++++++++++++++ .../WEXPushNotificationService.m | 127 ++++++++++--- 7 files changed, 311 insertions(+), 35 deletions(-) create mode 100644 WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.h create mode 100644 WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m diff --git a/Extension App/ContentExtension/Info.plist b/Extension App/ContentExtension/Info.plist index 6a6feba..292984c 100644 --- a/Extension App/ContentExtension/Info.plist +++ b/Extension App/ContentExtension/Info.plist @@ -38,9 +38,17 @@ WEG_BANNER_V6 WEG_BANNER_V7 WEG_BANNER_V8 + WEG_TEXT_V1 + WEG_TEXT_V2 + WEG_TEXT_V3 + WEG_TEXT_V4 + WEG_TEXT_V5 + WEG_TEXT_V6 + WEG_TEXT_V7 + WEG_TEXT_V8 UNNotificationExtensionInitialContentSizeRatio - 1 + 0.5 NSExtensionMainStoryboard MainInterface diff --git a/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj b/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj index 8e79262..36a5f29 100644 --- a/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj +++ b/Extension App/WEGExtensionApp.xcodeproj/project.pbxproj @@ -62,12 +62,14 @@ 56A49FB8EB9E003121E4C723 /* Pods-WEGExtensionApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WEGExtensionApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WEGExtensionApp/Pods-WEGExtensionApp.debug.xcconfig"; sourceTree = ""; }; 8167C6E259A361F9B2183151 /* libPods-WEGExtensionApp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WEGExtensionApp.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 8288374F4CC9F6A69DC1929F /* Pods-ContentExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ContentExtension/Pods-ContentExtension.debug.xcconfig"; sourceTree = ""; }; - A6F5D066278D6EA1005A96AA /* WEXBannerPushNotificationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WEXBannerPushNotificationViewController.h; sourceTree = ""; }; - A6F5D067278D6EAE005A96AA /* WEXBannerPushNotificationViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WEXBannerPushNotificationViewController.m; sourceTree = ""; }; A67089DF27A019E200DF27AC /* UIColor+DarkMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIColor+DarkMode.h"; sourceTree = ""; }; A67089E027A019EF00DF27AC /* UIColor+DarkMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIColor+DarkMode.m"; sourceTree = ""; }; + A693721927C0134F00045C60 /* WEXTextPushNotificationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WEXTextPushNotificationViewController.h; sourceTree = ""; }; + A693721A27C0135D00045C60 /* WEXTextPushNotificationViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WEXTextPushNotificationViewController.m; sourceTree = ""; }; A6DDEE99279A7A8D007FADE1 /* NSMutableAttributedString+Additions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableAttributedString+Additions.h"; sourceTree = ""; }; A6DDEE9A279A7B22007FADE1 /* NSMutableAttributedString+Additions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableAttributedString+Additions.m"; sourceTree = ""; }; + A6F5D066278D6EA1005A96AA /* WEXBannerPushNotificationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WEXBannerPushNotificationViewController.h; sourceTree = ""; }; + A6F5D067278D6EAE005A96AA /* WEXBannerPushNotificationViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WEXBannerPushNotificationViewController.m; sourceTree = ""; }; B554331A99838E3647290F86 /* Pods-ServiceExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ServiceExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ServiceExtension/Pods-ServiceExtension.debug.xcconfig"; sourceTree = ""; }; BF5C12043F19FA4C36D82355 /* Pods-WEGExtensionApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WEGExtensionApp.release.xcconfig"; path = "Pods/Target Support Files/Pods-WEGExtensionApp/Pods-WEGExtensionApp.release.xcconfig"; sourceTree = ""; }; CF34E9CCD03C284D4C70479B /* Pods-ContentExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentExtension.release.xcconfig"; path = "Pods/Target Support Files/Pods-ContentExtension/Pods-ContentExtension.release.xcconfig"; sourceTree = ""; }; @@ -277,6 +279,8 @@ A6DDEE9A279A7B22007FADE1 /* NSMutableAttributedString+Additions.m */, A67089DF27A019E200DF27AC /* UIColor+DarkMode.h */, A67089E027A019EF00DF27AC /* UIColor+DarkMode.m */, + A693721927C0134F00045C60 /* WEXTextPushNotificationViewController.h */, + A693721A27C0135D00045C60 /* WEXTextPushNotificationViewController.m */, ); path = ContentExtension; sourceTree = ""; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m index 787441b..3180ef9 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -19,8 +19,6 @@ @interface WEXBannerPushNotificationViewController () #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 @property (nonatomic) UNNotification *notification; -@property (nonatomic) NSUserDefaults *richPushDefaults; -@property (nonatomic) UIView *labelsContainerView; #endif diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index 262d4cb..5d5105b 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -10,6 +10,7 @@ #import "WEXCarouselPushNotificationViewController.h" #import "WEXRatingPushNotificationViewController.h" #import "WEXBannerPushNotificationViewController.h" +#import "WEXTextPushNotificationViewController.h" #import "WEXRichPushLayout.h" #import #import @@ -129,6 +130,8 @@ - (WEXRichPushLayout *)layoutForStyle:(NSString *)style { return [[WEXRatingPushNotificationViewController alloc] initWithNotificationViewController:self]; } else if (style && [style isEqualToString:@"BIG_PICTURE"]) { return [[WEXBannerPushNotificationViewController alloc] initWithNotificationViewController:self]; + } else if (style && [style isEqualToString:@"BIG_TEXT"]) { + return [[WEXTextPushNotificationViewController alloc] initWithNotificationViewController:self]; } return nil; } diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.h b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.h new file mode 100644 index 0000000..00c2247 --- /dev/null +++ b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.h @@ -0,0 +1,24 @@ +// +// WEXTextPushNotificationViewController.h +// WebEngage +// +// Copyright (c) 2022 Webklipper Technologies Pvt Ltd. All rights reserved. +// + +#import + +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 +#import +#import +#import "WEXRichPushNotificationViewController+Private.h" +#import "WEXRichPushLayout.h" +#endif + +@interface WEXTextPushNotificationViewController +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 +: WEXRichPushLayout +#else +: NSObject +#endif + +@end diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m new file mode 100644 index 0000000..59fd9a9 --- /dev/null +++ b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m @@ -0,0 +1,172 @@ +// +// WEXTextPushNotificationViewController.m +// WebEngage +// +// Copyright (c) 2022 Webklipper Technologies Pvt Ltd. All rights reserved. +// + +#import "WEXTextPushNotificationViewController.h" +#import "WEXRichPushNotificationViewController+Private.h" +#import "UIColor+DarkMode.h" + +#define CONTENT_PADDING 10 +#define TITLE_BODY_SPACE 5 +#define LANDSCAPE_ASPECT 0.5 + +API_AVAILABLE(ios(10.0)) +@interface WEXTextPushNotificationViewController () + +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 + +@property (nonatomic) UNNotification *notification; + +#endif + +@end + +@implementation WEXTextPushNotificationViewController + +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 + +- (void)didReceiveNotification:(UNNotification *)notification API_AVAILABLE(ios(10.0)) { + self.notification = notification; + [self initialiseViewHierarchy]; +} + +- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion{ + completion(UNNotificationContentExtensionResponseOptionDismissAndForwardAction); +} + +- (void)initialiseViewHierarchy { + self.view.backgroundColor = [UIColor WEXWhiteColor]; + + UIView *superViewWrapper = [[UIView alloc] init]; + [self.view addSubview:superViewWrapper]; + + [self setupLabelsContainer]; +} + +- (void)setupLabelsContainer { + UIView *superViewWrapper = self.view.subviews[0]; + NSString *colorHex = self.notification.request.content.userInfo[@"expandableDetails"][@"bckColor"]; + + UIView *richContentView = [[UIView alloc] init]; + richContentView.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXWhiteColor]; + + NSDictionary *expandedDetails = self.notification.request.content.userInfo[@"expandableDetails"]; + NSString *title = expandedDetails[@"rt"]; + NSString *subtitle = expandedDetails[@"rst"]; + NSString *message = expandedDetails[@"rm"]; + + BOOL titlePresent = title && ![title isEqualToString:@""]; + BOOL subTitlePresent = subtitle && ![subtitle isEqualToString:@""]; + BOOL messagePresent = message && ![message isEqualToString:@""]; + + if (!titlePresent) { + title = self.notification.request.content.title; + } + if (!subTitlePresent) { + subtitle = self.notification.request.content.subtitle; + } + if (!messagePresent) { + message = self.notification.request.content.body; + } + + UILabel *richTitleLabel = [[UILabel alloc] init]; + richTitleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES]; + richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; + + UILabel *richSubLabel = [[UILabel alloc] init]; + richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO]; + richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; + + UILabel *richBodyLabel = [[UILabel alloc] init]; + richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; + richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; + richBodyLabel.numberOfLines = 0; + + [richContentView addSubview:richTitleLabel]; + [richContentView addSubview:richSubLabel]; + [richContentView addSubview:richBodyLabel]; + + [superViewWrapper addSubview:richContentView]; + + [self setupConstraints]; +} + +- (void)setupConstraints { + UIView *superViewWrapper = self.view.subviews[0]; + UIView *richContentView = superViewWrapper.subviews[0]; + + if (@available(iOS 10.0, *)) { + superViewWrapper.translatesAutoresizingMaskIntoConstraints = NO; + [superViewWrapper.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES; + [superViewWrapper.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES; + [superViewWrapper.topAnchor constraintEqualToAnchor:self.view.topAnchor].active = YES; + [superViewWrapper.bottomAnchor constraintEqualToAnchor:richContentView.bottomAnchor].active = YES; + + richContentView.translatesAutoresizingMaskIntoConstraints = NO; + [richContentView.leadingAnchor constraintEqualToAnchor:superViewWrapper.leadingAnchor].active = YES; + [richContentView.trailingAnchor constraintEqualToAnchor:superViewWrapper.trailingAnchor].active = YES; + [richContentView.topAnchor constraintEqualToAnchor:superViewWrapper.topAnchor].active = YES; + + [self.viewController.bottomLayoutGuide.topAnchor constraintEqualToAnchor:superViewWrapper.bottomAnchor].active = YES; + + //Rich View labels + UIView *richTitleLabel = richContentView.subviews[0]; + UIView *richSubTitleLabel = richContentView.subviews[1]; + UIView *richBodyLabel = richContentView.subviews[2]; + + richTitleLabel.translatesAutoresizingMaskIntoConstraints = NO; + [richTitleLabel.leadingAnchor + constraintEqualToAnchor:richContentView.leadingAnchor + constant:CONTENT_PADDING] + .active = YES; + [richTitleLabel.trailingAnchor + constraintEqualToAnchor:richContentView.trailingAnchor + constant:0 - CONTENT_PADDING] + .active = YES; + [richTitleLabel.topAnchor + constraintEqualToAnchor:richContentView.topAnchor + constant:CONTENT_PADDING] + .active = YES; + + richSubTitleLabel.translatesAutoresizingMaskIntoConstraints = NO; + [richSubTitleLabel.leadingAnchor + constraintEqualToAnchor:richContentView.leadingAnchor + constant:CONTENT_PADDING] + .active = YES; + [richSubTitleLabel.trailingAnchor + constraintEqualToAnchor:richContentView.trailingAnchor + constant:0 - CONTENT_PADDING] + .active = YES; + [richSubTitleLabel.topAnchor + constraintEqualToAnchor:richTitleLabel.bottomAnchor + constant:0] + .active = YES; + + richBodyLabel.translatesAutoresizingMaskIntoConstraints = NO; + [richBodyLabel.leadingAnchor + constraintEqualToAnchor:richContentView.leadingAnchor + constant:CONTENT_PADDING] + .active = YES; + [richBodyLabel.trailingAnchor + constraintEqualToAnchor:richContentView.trailingAnchor + constant:0 - CONTENT_PADDING] + .active = YES; + [richBodyLabel.topAnchor constraintEqualToAnchor:richSubTitleLabel.bottomAnchor + constant:0] + .active = YES; + [richBodyLabel.bottomAnchor + constraintEqualToAnchor:richContentView.bottomAnchor + constant:-CONTENT_PADDING] + .active = YES; + } else { + NSLog(@"Expected to be running iOS version 10 or above"); + } +} + +#endif + +@end + diff --git a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m index 743a1d1..3941cff 100644 --- a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m +++ b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m @@ -18,6 +18,7 @@ @interface WEXPushNotificationService () @property (nonatomic) NSString *enviroment; @property NSDictionary *sharedUserDefaults; @property NSArray *bannerCategories; +@property NSArray *textCategories; #endif @end @@ -35,11 +36,10 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request self.contentHandler = contentHandler; self.bestAttemptContent = [request.content mutableCopy]; - - self.bannerCategories = @[@"WEG_BANNER_V1", @"WEG_BANNER_V2", @"WEG_BANNER_V3", @"WEG_BANNER_V4", @"WEG_BANNER_V5", @"WEG_BANNER_V6", @"WEG_BANNER_V7", @"WEG_BANNER_V8"]; [self setExtensionDefaults]; NSLog(@"Push Notification content: %@", request.content.userInfo); + NSLog(@"CategoryId: %@", self.bestAttemptContent.categoryIdentifier); NSDictionary *expandableDetails = request.content.userInfo[@"expandableDetails"]; @@ -52,7 +52,9 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request [self drawBannerViewWith:expandableDetails[@"image"]]; } else if (expandableDetails && style && [style isEqualToString:@"BIG_PICTURE"]) { - NSString *bannerCatName = [self getBannerCategoryFor:self.bestAttemptContent.categoryIdentifier]; + self.bannerCategories = @[@"WEG_BANNER_V1", @"WEG_BANNER_V2", @"WEG_BANNER_V3", @"WEG_BANNER_V4", @"WEG_BANNER_V5", @"WEG_BANNER_V6", @"WEG_BANNER_V7", @"WEG_BANNER_V8"]; + + NSString *bannerCatName = [self getCategoryFor:self.bannerCategories currentCategory:self.bestAttemptContent.categoryIdentifier]; UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; [center getNotificationCategoriesWithCompletionHandler:^(NSSet *existingCategories) { @@ -107,6 +109,67 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request }); }]; + } else if (expandableDetails && style && [style isEqualToString:@"BIG_TEXT"]) { + self.textCategories = @[@"WEG_TEXT_V1", @"WEG_TEXT_V2", @"WEG_TEXT_V3", @"WEG_TEXT_V4", @"WEG_TEXT_V5", @"WEG_TEXT_V6", @"WEG_TEXT_V7", @"WEG_TEXT_V8"]; + NSString *textCatName = [self getCategoryFor:self.textCategories currentCategory:self.bestAttemptContent.categoryIdentifier]; + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + + [center getNotificationCategoriesWithCompletionHandler:^(NSSet *existingCategories) { + UNNotificationCategory *currentCategory; + BOOL isLayoutRegistered = NO; + BOOL isCurrentCatBanner = NO; + NSMutableSet *existingMutablecat = [[NSMutableSet alloc] init]; + + for(UNNotificationCategory *dict in existingCategories) { + if([dict.identifier isEqual: self.bestAttemptContent.categoryIdentifier]) { + currentCategory = dict; + isLayoutRegistered = [dict.identifier isEqualToString:textCatName]; + isCurrentCatBanner = [self.bannerCategories containsObject:dict.identifier]; + } else { + [existingMutablecat addObject:dict]; + } + } + + if (isLayoutRegistered) { + if (!isCurrentCatBanner) { + [self.bestAttemptContent setCategoryIdentifier:textCatName]; + } + [self trackEventWithCompletion:^{ + self.contentHandler(self.bestAttemptContent); + }]; + return; + } + + // Register text layout here. + NSMutableArray *actions = [NSMutableArray arrayWithCapacity:currentCategory.actions.count]; + + for (UNNotificationAction *action in currentCategory.actions) { + UNNotificationAction *actionObject = [UNNotificationAction actionWithIdentifier:action.identifier + title:action.title + options:action.options]; + [actions addObject:actionObject]; + } + + UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:textCatName + actions:actions + intentIdentifiers:@[] + options:UNNotificationCategoryOptionCustomDismissAction]; + [existingMutablecat addObject:category]; + [center setNotificationCategories:existingMutablecat]; + [self.bestAttemptContent setCategoryIdentifier:textCatName]; + /* + Dispatching on Main thread after 2 sec delay to make sure our category is registered with NotificationCenter + Registering will make sure, contentHandler will invoke ContentExtension with this custom category + + NOTE: Use this workaround till we receive banner category in network response. + */ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [self trackEventWithCompletion:^{ + self.contentHandler(self.bestAttemptContent); + }]; + }); + }]; + } else { [self trackEventWithCompletion:^{ self.contentHandler(self.bestAttemptContent); @@ -114,19 +177,29 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request } } +- (void)serviceExtensionTimeWillExpire { + NSLog(@"%@", @(__FUNCTION__)); + self.contentHandler(self.bestAttemptContent); +} + + +#pragma mark - Text Layout + +#pragma mark - Banner Layout + // NOTE: This mapping is a temporary workaround, Will be removed in future releases -- (NSString *)getBannerCategoryFor:(NSString *)currentCategory { +- (NSString *)getCategoryFor:(NSArray *)categories currentCategory:(NSString *)currentCategory { NSDictionary *bannerMapping = @{ - @"default" : self.bannerCategories[0], - @"19db52de" : self.bannerCategories[0], - @"18dfbbcc" : self.bannerCategories[1], - @"16589g0g" : self.bannerCategories[2], - @"15ead296" : self.bannerCategories[3], - @"17543720" : self.bannerCategories[4], - @"16e66ba8" : self.bannerCategories[5], - @"1c406g7a" : self.bannerCategories[6], - @"1bd2a2g0" : self.bannerCategories[7] + @"default" : categories[0], // Default, No buttons + @"19db52de": categories[0], // Default, No buttons + @"18dfbbcc": categories[1], // Yes/No - Open App/Dismiss + @"16589g0g": categories[2], // Yes/No - Dismiss both + @"15ead296": categories[3], // Accept/Decline - Open/Dismiss + @"17543720": categories[4], // Accept/Decline - Dismiss both + @"16e66ba8": categories[5], // Shop Now + @"1c406g7a": categories[6], // Buy Now + @"1bd2a2g0": categories[7] // Download Now }; NSString *category = bannerMapping[currentCategory]; @@ -137,22 +210,6 @@ - (NSString *)getBannerCategoryFor:(NSString *)currentCategory { } } -- (void)setExtensionDefaults { - NSUserDefaults *sharedDefaults = [self getSharedUserDefaults]; - // Write operation only if key is not present in the UserDefaults - - if ([sharedDefaults valueForKey:@"WEG_ServiceToApp"] == nil) { - [sharedDefaults setValue:@"WEG" forKey:@"WEG_ServiceToApp"]; - [sharedDefaults synchronize]; - } -} - -- (void)serviceExtensionTimeWillExpire { - NSLog(@"%@", @(__FUNCTION__)); - self.contentHandler(self.bestAttemptContent); -} - - #pragma mark - Rich Push View Helpers - (void)drawCarouselViewWith:(NSArray *)items { @@ -285,12 +342,22 @@ - (void)trackEventWithCompletion:(void(^)(void))completion { }] resume]; } +- (void)setExtensionDefaults { + NSUserDefaults *sharedDefaults = [self getSharedUserDefaults]; + // Write operation only if key is not present in the UserDefaults + + if ([sharedDefaults valueForKey:@"WEG_ServiceToApp"] == nil) { + [sharedDefaults setValue:@"WEG" forKey:@"WEG_ServiceToApp"]; + [sharedDefaults synchronize]; + } +} + - (NSString *) getBaseURL{ NSString *baseURL = @"https://c.webengage.com/tracker"; [self setDataFromSharedUserDefaults]; - NSLog(@"Setting Enviroment to : %@",self.enviroment); + NSLog(@"Setting Enviroment to: %@",self.enviroment); if ([self.enviroment.uppercaseString isEqualToString:@"IN"]) { baseURL = @"https://c.in.webengage.com/tracker"; From b810f5586246e10f76730ecca25f7c22c865657f Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Sat, 19 Feb 2022 17:14:04 +0530 Subject: [PATCH 21/28] Multiline enabled for all rich text labels added --- .../ContentExtension/WEXBannerPushNotificationViewController.m | 2 ++ .../WEXCarouselPushNotificationViewController.m | 2 ++ .../ContentExtension/WEXRatingPushNotificationViewController.m | 3 ++- .../ContentExtension/WEXTextPushNotificationViewController.m | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m index 3180ef9..46df5a1 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -119,10 +119,12 @@ - (void)setupLabelsContainer { UILabel *richTitleLabel = [[UILabel alloc] init]; richTitleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; + richTitleLabel.numberOfLines = 0; UILabel *richSubLabel = [[UILabel alloc] init]; richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; + richSubLabel.numberOfLines = 0; UILabel *richBodyLabel = [[UILabel alloc] init]; richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index 721d6f4..06479bd 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -329,10 +329,12 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES]; titleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; + titleLabel.numberOfLines = 0; UILabel *subTitleLabel = [[UILabel alloc] init]; subTitleLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO]; subTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; + subTitleLabel.numberOfLines = 0; UILabel *bodyLabel = [[UILabel alloc] init]; bodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index 8ec94fd..794f7aa 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -265,16 +265,17 @@ - (void)initialiseViewHierarchy { UILabel *richTitleLabel = [[UILabel alloc] init]; richTitleLabel.attributedText = [self.viewController getHtmlParsedString:richTitle isTitle:YES]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; + richTitleLabel.numberOfLines = 0; UILabel *richSubLabel = [[UILabel alloc] init]; richSubLabel.attributedText = [self.viewController getHtmlParsedString:richSub isTitle:NO]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; + richSubLabel.numberOfLines = 0; UILabel *richBodyLabel = [[UILabel alloc] init]; richBodyLabel.attributedText = [self.viewController getHtmlParsedString:richMessage isTitle:NO]; richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; richBodyLabel.numberOfLines = 0; - [richContentView addSubview:richTitleLabel]; [richContentView addSubview:richSubLabel]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m index 59fd9a9..337b482 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m @@ -75,10 +75,12 @@ - (void)setupLabelsContainer { UILabel *richTitleLabel = [[UILabel alloc] init]; richTitleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; + richTitleLabel.numberOfLines = 0; UILabel *richSubLabel = [[UILabel alloc] init]; richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; + richSubLabel.numberOfLines = 0; UILabel *richBodyLabel = [[UILabel alloc] init]; richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; From fd8d987d9687818a60c25f100499ecab03c59f20 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Sat, 19 Feb 2022 19:58:24 +0530 Subject: [PATCH 22/28] All images download enabled for carousal layout in ServiceExtension --- .../WEXPushNotificationService.m | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m index 743a1d1..c01ae23 100644 --- a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m +++ b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m @@ -159,36 +159,37 @@ - (void)drawCarouselViewWith:(NSArray *)items { NSMutableArray *attachmentsArray = [[NSMutableArray alloc] initWithCapacity:items.count]; - if (items.count >= 3) { - NSUInteger itemCounter = 0; - NSUInteger __block imageDownloadAttemptCounter = 0; + if (items.count <= 0) { + return; + } + + NSUInteger itemCounter = 0; + NSUInteger __block imageDownloadAttemptCounter = 0; + + for (NSDictionary *carouselItem in items) { - for (NSDictionary *carouselItem in items) { + NSString *imageURL = carouselItem[@"image"]; + + [self fetchAttachmentFor:imageURL + at:itemCounter + completionHandler:^(UNNotificationAttachment *attachment, NSUInteger index) { - NSString *imageURL = carouselItem[@"image"]; + imageDownloadAttemptCounter++; - [self fetchAttachmentFor:imageURL - at:itemCounter - completionHandler:^(UNNotificationAttachment *attachment, NSUInteger index) { - - imageDownloadAttemptCounter++; - - if (attachment) { - NSLog(@"Downloaded Attachment No. %ld", (unsigned long)index); - [attachmentsArray addObject:attachment]; - self.bestAttemptContent.attachments = attachmentsArray; - } - - if (imageDownloadAttemptCounter == items.count) { - - [self trackEventWithCompletion:^{ - NSLog(@"Ending WebEngage Rich Push Service"); - self.contentHandler(self.bestAttemptContent); - }]; - } - }]; - itemCounter++; - } + if (attachment) { + NSLog(@"Downloaded Attachment No. %ld", (unsigned long)index); + [attachmentsArray addObject:attachment]; + self.bestAttemptContent.attachments = attachmentsArray; + } + + if (imageDownloadAttemptCounter == items.count) { + [self trackEventWithCompletion:^{ + NSLog(@"Ending WebEngage Rich Push Service"); + self.contentHandler(self.bestAttemptContent); + }]; + } + }]; + itemCounter++; } } From 17b7dd4f48466830a57e7d9bfd2be6a7e3e6c725 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Mon, 21 Feb 2022 12:12:24 +0530 Subject: [PATCH 23/28] Layout mapping updated --- Extension App/ContentExtension/Info.plist | 112 ++++++++--------- .../WEXPushNotificationService.m | 113 ++++-------------- 2 files changed, 78 insertions(+), 147 deletions(-) diff --git a/Extension App/ContentExtension/Info.plist b/Extension App/ContentExtension/Info.plist index 292984c..337085a 100644 --- a/Extension App/ContentExtension/Info.plist +++ b/Extension App/ContentExtension/Info.plist @@ -1,64 +1,56 @@ - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleDisplayName - ContentExtension - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - XPC! - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - NSExtension - - NSExtensionAttributes - - UNNotificationExtensionDefaultContentHidden - - UNNotificationExtensionCategory - - WEG_CAROUSEL_V1 - WEG_RATING_V1 - WEG_BANNER_V1 - WEG_BANNER_V2 - WEG_BANNER_V3 - WEG_BANNER_V4 - WEG_BANNER_V5 - WEG_BANNER_V6 - WEG_BANNER_V7 - WEG_BANNER_V8 - WEG_TEXT_V1 - WEG_TEXT_V2 - WEG_TEXT_V3 - WEG_TEXT_V4 - WEG_TEXT_V5 - WEG_TEXT_V6 - WEG_TEXT_V7 - WEG_TEXT_V8 - - UNNotificationExtensionInitialContentSizeRatio - 0.5 - - NSExtensionMainStoryboard - MainInterface - NSExtensionPointIdentifier - com.apple.usernotifications.content-extension - - NSAppTransportSecurity - - NSAllowsArbitraryLoads - - - + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + ContentExtension + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSExtension + + NSExtensionAttributes + + UNNotificationExtensionDefaultContentHidden + + UNNotificationExtensionCategory + + WEG_CAROUSEL_V1 + WEG_RATING_V1 + WEG_RICH_V1 + WEG_RICH_V2 + WEG_RICH_V3 + WEG_RICH_V4 + WEG_RICH_V5 + WEG_RICH_V6 + WEG_RICH_V7 + WEG_RICH_V8 + + UNNotificationExtensionInitialContentSizeRatio + 1 + + NSExtensionMainStoryboard + MainInterface + NSExtensionPointIdentifier + com.apple.usernotifications.content-extension + + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + diff --git a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m index 6930e62..d908442 100644 --- a/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m +++ b/WebEngageAppEx/Classes/NotificationService/WEXPushNotificationService.m @@ -17,8 +17,7 @@ @interface WEXPushNotificationService () @property (nonatomic) UNMutableNotificationContent *bestAttemptContent; @property (nonatomic) NSString *enviroment; @property NSDictionary *sharedUserDefaults; -@property NSArray *bannerCategories; -@property NSArray *textCategories; +@property NSArray *customCategories; #endif @end @@ -39,45 +38,43 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request [self setExtensionDefaults]; NSLog(@"Push Notification content: %@", request.content.userInfo); - NSLog(@"CategoryId: %@", self.bestAttemptContent.categoryIdentifier); NSDictionary *expandableDetails = request.content.userInfo[@"expandableDetails"]; - NSString *style = expandableDetails[@"style"]; if (expandableDetails && style && [style isEqualToString:@"CAROUSEL_V1"]) { [self drawCarouselViewWith:expandableDetails[@"items"]]; } else if (expandableDetails && style && [style isEqualToString:@"RATING_V1"]) { - [self drawBannerViewWith:expandableDetails[@"image"]]; + [self handleContentFor:style image:expandableDetails[@"image"]]; - } else if (expandableDetails && style && [style isEqualToString:@"BIG_PICTURE"]) { - self.bannerCategories = @[@"WEG_BANNER_V1", @"WEG_BANNER_V2", @"WEG_BANNER_V3", @"WEG_BANNER_V4", @"WEG_BANNER_V5", @"WEG_BANNER_V6", @"WEG_BANNER_V7", @"WEG_BANNER_V8"]; + } else if (expandableDetails && style && ([style isEqualToString:@"BIG_PICTURE"] || [style isEqualToString:@"BIG_TEXT"])) { + self.customCategories = @[@"WEG_RICH_V1", @"WEG_RICH_V2", @"WEG_RICH_V3", @"WEG_RICH_V4", @"WEG_RICH_V5", @"WEG_RICH_V6", @"WEG_RICH_V7", @"WEG_RICH_V8"]; - NSString *bannerCatName = [self getCategoryFor:self.bannerCategories currentCategory:self.bestAttemptContent.categoryIdentifier]; + NSString *customCategory = [self getCategoryFor:self.customCategories currentCategory:self.bestAttemptContent.categoryIdentifier]; UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; [center getNotificationCategoriesWithCompletionHandler:^(NSSet *existingCategories) { UNNotificationCategory *currentCategory; - BOOL isBannerRegistered = NO; - BOOL isCurrentCatBanner = NO; + BOOL isCategoryRegistered = NO; + BOOL isCurrentCatCustom = NO; NSMutableSet *existingMutablecat = [[NSMutableSet alloc] init]; for(UNNotificationCategory *dict in existingCategories) { if([dict.identifier isEqual: self.bestAttemptContent.categoryIdentifier]) { currentCategory = dict; - isBannerRegistered = [dict.identifier isEqualToString:bannerCatName]; - isCurrentCatBanner = [self.bannerCategories containsObject:dict.identifier]; + isCategoryRegistered = [dict.identifier isEqualToString:customCategory]; + isCurrentCatCustom = [self.customCategories containsObject:dict.identifier]; } else { [existingMutablecat addObject:dict]; } } - if (isBannerRegistered) { - if (!isCurrentCatBanner) { - [self.bestAttemptContent setCategoryIdentifier:bannerCatName]; + if (isCategoryRegistered) { + if (!isCurrentCatCustom) { + [self.bestAttemptContent setCategoryIdentifier:customCategory]; } - [self drawBannerViewWith:expandableDetails[@"image"]]; + [self handleContentFor:style image:expandableDetails[@"image"]]; return; } @@ -91,13 +88,13 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request [actions addObject:actionObject]; } - UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:bannerCatName + UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:customCategory actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction]; [existingMutablecat addObject:category]; [center setNotificationCategories:existingMutablecat]; - [self.bestAttemptContent setCategoryIdentifier:bannerCatName]; + [self.bestAttemptContent setCategoryIdentifier:customCategory]; /* Dispatching on Main thread after 2 sec delay to make sure our category is registered with NotificationCenter Registering will make sure, contentHandler will invoke ContentExtension with this custom category @@ -105,71 +102,18 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request NOTE: Use this workaround till we receive banner category in network response. */ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ - [self drawBannerViewWith:expandableDetails[@"image"]]; + [self handleContentFor:style image:expandableDetails[@"image"]]; }); }]; - } else if (expandableDetails && style && [style isEqualToString:@"BIG_TEXT"]) { - self.textCategories = @[@"WEG_TEXT_V1", @"WEG_TEXT_V2", @"WEG_TEXT_V3", @"WEG_TEXT_V4", @"WEG_TEXT_V5", @"WEG_TEXT_V6", @"WEG_TEXT_V7", @"WEG_TEXT_V8"]; - NSString *textCatName = [self getCategoryFor:self.textCategories currentCategory:self.bestAttemptContent.categoryIdentifier]; - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - - [center getNotificationCategoriesWithCompletionHandler:^(NSSet *existingCategories) { - UNNotificationCategory *currentCategory; - BOOL isLayoutRegistered = NO; - BOOL isCurrentCatBanner = NO; - NSMutableSet *existingMutablecat = [[NSMutableSet alloc] init]; - - for(UNNotificationCategory *dict in existingCategories) { - if([dict.identifier isEqual: self.bestAttemptContent.categoryIdentifier]) { - currentCategory = dict; - isLayoutRegistered = [dict.identifier isEqualToString:textCatName]; - isCurrentCatBanner = [self.bannerCategories containsObject:dict.identifier]; - } else { - [existingMutablecat addObject:dict]; - } - } - - if (isLayoutRegistered) { - if (!isCurrentCatBanner) { - [self.bestAttemptContent setCategoryIdentifier:textCatName]; - } - [self trackEventWithCompletion:^{ - self.contentHandler(self.bestAttemptContent); - }]; - return; - } - - // Register text layout here. - NSMutableArray *actions = [NSMutableArray arrayWithCapacity:currentCategory.actions.count]; - - for (UNNotificationAction *action in currentCategory.actions) { - UNNotificationAction *actionObject = [UNNotificationAction actionWithIdentifier:action.identifier - title:action.title - options:action.options]; - [actions addObject:actionObject]; - } - - UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:textCatName - actions:actions - intentIdentifiers:@[] - options:UNNotificationCategoryOptionCustomDismissAction]; - [existingMutablecat addObject:category]; - [center setNotificationCategories:existingMutablecat]; - [self.bestAttemptContent setCategoryIdentifier:textCatName]; - /* - Dispatching on Main thread after 2 sec delay to make sure our category is registered with NotificationCenter - Registering will make sure, contentHandler will invoke ContentExtension with this custom category - - NOTE: Use this workaround till we receive banner category in network response. - */ - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ - [self trackEventWithCompletion:^{ - self.contentHandler(self.bestAttemptContent); - }]; - }); - }]; - + } else { + [self handleContentFor:style image:@""]; + } +} + +- (void)handleContentFor:(NSString *)style image:(NSString *)image { + if ([style isEqualToString:@"BIG_PICTURE"] || [style isEqualToString:@"RATING_V1"]) { + [self drawBannerViewWith:image]; } else { [self trackEventWithCompletion:^{ self.contentHandler(self.bestAttemptContent); @@ -182,15 +126,10 @@ - (void)serviceExtensionTimeWillExpire { self.contentHandler(self.bestAttemptContent); } - -#pragma mark - Text Layout - -#pragma mark - Banner Layout - // NOTE: This mapping is a temporary workaround, Will be removed in future releases - (NSString *)getCategoryFor:(NSArray *)categories currentCategory:(NSString *)currentCategory { - NSDictionary *bannerMapping = @{ + NSDictionary *categoryMapping = @{ @"default" : categories[0], // Default, No buttons @"19db52de": categories[0], // Default, No buttons @"18dfbbcc": categories[1], // Yes/No - Open App/Dismiss @@ -202,7 +141,7 @@ - (NSString *)getCategoryFor:(NSArray *)categories currentCategory:(NSString *)c @"1bd2a2g0": categories[7] // Download Now }; - NSString *category = bannerMapping[currentCategory]; + NSString *category = categoryMapping[currentCategory]; if (category) { return category; } else { From 704c4ea9168da734ca902ecbd7019c4ef951c497 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Mon, 21 Feb 2022 23:16:04 +0530 Subject: [PATCH 24/28] Added workaround for issue where html parsing adds black text colour on dark mode. --- .../NSMutableAttributedString+Additions.h | 2 + .../NSMutableAttributedString+Additions.m | 38 ++++++++++++++++++- .../WEXBannerPushNotificationViewController.m | 6 +-- ...EXCarouselPushNotificationViewController.m | 6 +-- .../WEXRatingPushNotificationViewController.m | 6 +-- ...chPushNotificationViewController+Private.h | 2 +- .../WEXRichPushNotificationViewController.m | 7 +++- .../WEXTextPushNotificationViewController.m | 6 +-- 8 files changed, 58 insertions(+), 15 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h index 6f0addd..76b791d 100644 --- a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h +++ b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.h @@ -9,6 +9,8 @@ @interface NSMutableAttributedString (Additions) +- (void)updateDefaultTextColor; + - (void)setFontFaceWithFont:(UIFont *)font; - (void)trimWhiteSpace; diff --git a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m index 6d8acc6..5498239 100644 --- a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m +++ b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m @@ -5,11 +5,47 @@ // Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved. // -#import +#import #import "NSMutableAttributedString+Additions.h" +#import "UIColor+DarkMode.h" @implementation NSMutableAttributedString (Additions) +- (void)updateDefaultTextColor { + [self beginEditing]; + [self enumerateAttribute:NSForegroundColorAttributeName + inRange:NSMakeRange(0, self.length) + options:0 + usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { + UIColor *color = (UIColor *)value; + UIColor *labelColor = [UIColor WEXLabelColor]; + NSString *colorHex = [self hexStringFromColor:color]; + + if (@available(iOS 12.0, *)) { + if (UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { + if ([colorHex isEqualToString:@"#000000"]) { + [self removeAttribute:NSForegroundColorAttributeName range:range]; + [self addAttribute:NSForegroundColorAttributeName value:labelColor range:range]; + } + } + } + }]; + [self endEditing]; +} + +- (NSString *)hexStringFromColor:(UIColor *)color { + const CGFloat *components = CGColorGetComponents(color.CGColor); + + CGFloat r = components[0]; + CGFloat g = components[1]; + CGFloat b = components[2]; + + return [NSString stringWithFormat:@"#%02lX%02lX%02lX", + lroundf(r * 255), + lroundf(g * 255), + lroundf(b * 255)]; +} + - (void)setFontFaceWithFont:(UIFont *)font { [self beginEditing]; [self enumerateAttribute:NSFontAttributeName diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m index 46df5a1..eb57ce1 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -117,17 +117,17 @@ - (void)setupLabelsContainer { } UILabel *richTitleLabel = [[UILabel alloc] init]; - richTitleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES]; + richTitleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES bckColor:colorHex]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; richTitleLabel.numberOfLines = 0; UILabel *richSubLabel = [[UILabel alloc] init]; - richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO]; + richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO bckColor:colorHex]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; richSubLabel.numberOfLines = 0; UILabel *richBodyLabel = [[UILabel alloc] init]; - richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; + richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO bckColor:colorHex]; richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; richBodyLabel.numberOfLines = 0; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index 06479bd..6d0b88e 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -327,17 +327,17 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA notificationContentView.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXWhiteColor]; UILabel *titleLabel = [[UILabel alloc] init]; - titleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES]; + titleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES bckColor:colorHex]; titleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; titleLabel.numberOfLines = 0; UILabel *subTitleLabel = [[UILabel alloc] init]; - subTitleLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO]; + subTitleLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO bckColor:colorHex]; subTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; subTitleLabel.numberOfLines = 0; UILabel *bodyLabel = [[UILabel alloc] init]; - bodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; + bodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO bckColor:colorHex]; bodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:bodyLabel.text]; bodyLabel.numberOfLines = 0; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index 794f7aa..ef3a8fe 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -263,17 +263,17 @@ - (void)initialiseViewHierarchy { richContentView.backgroundColor = [UIColor colorFromHexString:colorHex defaultColor:UIColor.WEXWhiteColor]; UILabel *richTitleLabel = [[UILabel alloc] init]; - richTitleLabel.attributedText = [self.viewController getHtmlParsedString:richTitle isTitle:YES]; + richTitleLabel.attributedText = [self.viewController getHtmlParsedString:richTitle isTitle:YES bckColor:colorHex]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; richTitleLabel.numberOfLines = 0; UILabel *richSubLabel = [[UILabel alloc] init]; - richSubLabel.attributedText = [self.viewController getHtmlParsedString:richSub isTitle:NO]; + richSubLabel.attributedText = [self.viewController getHtmlParsedString:richSub isTitle:NO bckColor:colorHex]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; richSubLabel.numberOfLines = 0; UILabel *richBodyLabel = [[UILabel alloc] init]; - richBodyLabel.attributedText = [self.viewController getHtmlParsedString:richMessage isTitle:NO]; + richBodyLabel.attributedText = [self.viewController getHtmlParsedString:richMessage isTitle:NO bckColor:colorHex]; richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; richBodyLabel.numberOfLines = 0; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h index 0b6526d..655063d 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController+Private.h @@ -26,7 +26,7 @@ - (NSTextAlignment)naturalTextAligmentForText:(NSString*) text; -- (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL)isTitle; +- (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL)isTitle bckColor:(NSString *)bckColor; #endif diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index 5d5105b..d0ec7e8 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -251,7 +251,7 @@ - (NSTextAlignment)naturalTextAligmentForText:(NSString*)text { } } -- (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL)isTitle { +- (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL)isTitle bckColor:(NSString *)bckColor { NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData: [textString dataUsingEncoding:NSUnicodeStringEncoding] options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } @@ -259,6 +259,11 @@ - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL error: nil ]; + BOOL hasBckColor = bckColor && ![bckColor isEqualToString:@""]; + if (!hasBckColor) { + [attributedString updateDefaultTextColor]; + } + BOOL containsHTML = [self containsHTML:textString]; BOOL containsFontSize = [textString rangeOfString:@"font-size"].location != NSNotFound; BOOL containsStrong = [textString rangeOfString:@""].location != NSNotFound; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m index 337b482..d4b231a 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m @@ -73,17 +73,17 @@ - (void)setupLabelsContainer { } UILabel *richTitleLabel = [[UILabel alloc] init]; - richTitleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES]; + richTitleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES bckColor:colorHex]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; richTitleLabel.numberOfLines = 0; UILabel *richSubLabel = [[UILabel alloc] init]; - richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO]; + richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO bckColor:colorHex]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; richSubLabel.numberOfLines = 0; UILabel *richBodyLabel = [[UILabel alloc] init]; - richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO]; + richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO bckColor:colorHex]; richBodyLabel.textAlignment = [self.viewController naturalTextAligmentForText:richBodyLabel.text]; richBodyLabel.numberOfLines = 0; From 948145a468133dc3874c1d06ef4228c6f43291d7 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Fri, 25 Feb 2022 15:23:54 +0530 Subject: [PATCH 25/28] Title, Subtitle updated for default number of lines for expanded state --- .../NSMutableAttributedString+Additions.m | 27 ++++++++++--------- .../WEXBannerPushNotificationViewController.m | 2 -- ...EXCarouselPushNotificationViewController.m | 2 -- .../WEXRatingPushNotificationViewController.m | 2 -- .../WEXTextPushNotificationViewController.m | 2 -- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m index 5498239..51f388f 100644 --- a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m +++ b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m @@ -12,25 +12,26 @@ @implementation NSMutableAttributedString (Additions) - (void)updateDefaultTextColor { - [self beginEditing]; - [self enumerateAttribute:NSForegroundColorAttributeName - inRange:NSMakeRange(0, self.length) - options:0 - usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { - UIColor *color = (UIColor *)value; - UIColor *labelColor = [UIColor WEXLabelColor]; - NSString *colorHex = [self hexStringFromColor:color]; - - if (@available(iOS 12.0, *)) { + if (@available(iOS 13.0, *)) { + [self beginEditing]; + [self enumerateAttribute:NSForegroundColorAttributeName + inRange:NSMakeRange(0, self.length) + options:0 + usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { + + UIColor *color = (UIColor *)value; + UIColor *labelColor = [UIColor WEXLabelColor]; + NSString *colorHex = [self hexStringFromColor:color]; + if (UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { if ([colorHex isEqualToString:@"#000000"]) { [self removeAttribute:NSForegroundColorAttributeName range:range]; [self addAttribute:NSForegroundColorAttributeName value:labelColor range:range]; } } - } - }]; - [self endEditing]; + }]; + [self endEditing]; + } } - (NSString *)hexStringFromColor:(UIColor *)color { diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m index eb57ce1..d3ecdfb 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -119,12 +119,10 @@ - (void)setupLabelsContainer { UILabel *richTitleLabel = [[UILabel alloc] init]; richTitleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES bckColor:colorHex]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; - richTitleLabel.numberOfLines = 0; UILabel *richSubLabel = [[UILabel alloc] init]; richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO bckColor:colorHex]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; - richSubLabel.numberOfLines = 0; UILabel *richBodyLabel = [[UILabel alloc] init]; richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO bckColor:colorHex]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index 6d0b88e..3fe1d1b 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -329,12 +329,10 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES bckColor:colorHex]; titleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; - titleLabel.numberOfLines = 0; UILabel *subTitleLabel = [[UILabel alloc] init]; subTitleLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO bckColor:colorHex]; subTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; - subTitleLabel.numberOfLines = 0; UILabel *bodyLabel = [[UILabel alloc] init]; bodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO bckColor:colorHex]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index ef3a8fe..f4901e4 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -265,12 +265,10 @@ - (void)initialiseViewHierarchy { UILabel *richTitleLabel = [[UILabel alloc] init]; richTitleLabel.attributedText = [self.viewController getHtmlParsedString:richTitle isTitle:YES bckColor:colorHex]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; - richTitleLabel.numberOfLines = 0; UILabel *richSubLabel = [[UILabel alloc] init]; richSubLabel.attributedText = [self.viewController getHtmlParsedString:richSub isTitle:NO bckColor:colorHex]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; - richSubLabel.numberOfLines = 0; UILabel *richBodyLabel = [[UILabel alloc] init]; richBodyLabel.attributedText = [self.viewController getHtmlParsedString:richMessage isTitle:NO bckColor:colorHex]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m index d4b231a..4b5ddef 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m @@ -75,12 +75,10 @@ - (void)setupLabelsContainer { UILabel *richTitleLabel = [[UILabel alloc] init]; richTitleLabel.attributedText = [self.viewController getHtmlParsedString:title isTitle:YES bckColor:colorHex]; richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; - richTitleLabel.numberOfLines = 0; UILabel *richSubLabel = [[UILabel alloc] init]; richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO bckColor:colorHex]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; - richSubLabel.numberOfLines = 0; UILabel *richBodyLabel = [[UILabel alloc] init]; richBodyLabel.attributedText = [self.viewController getHtmlParsedString:message isTitle:NO bckColor:colorHex]; From fae589065799e66a4d35d45709cae88443a5cb89 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Fri, 25 Feb 2022 20:03:35 +0530 Subject: [PATCH 26/28] Title-Subtitle updated to be bold for expanded state --- .../WEXBannerPushNotificationViewController.m | 2 +- ...EXCarouselPushNotificationViewController.m | 2 +- .../WEXRatingPushNotificationViewController.m | 2 +- .../WEXRichPushNotificationViewController.m | 21 ++++++++++++------- .../WEXTextPushNotificationViewController.m | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m index d3ecdfb..030bb01 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXBannerPushNotificationViewController.m @@ -121,7 +121,7 @@ - (void)setupLabelsContainer { richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; UILabel *richSubLabel = [[UILabel alloc] init]; - richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO bckColor:colorHex]; + richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:YES bckColor:colorHex]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; UILabel *richBodyLabel = [[UILabel alloc] init]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m index 3fe1d1b..8d1de2a 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXCarouselPushNotificationViewController.m @@ -331,7 +331,7 @@ - (void)initialiseCarouselForNotification:(UNNotification *)notification API_AVA titleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; UILabel *subTitleLabel = [[UILabel alloc] init]; - subTitleLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO bckColor:colorHex]; + subTitleLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:YES bckColor:colorHex]; subTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:titleLabel.text]; UILabel *bodyLabel = [[UILabel alloc] init]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m index f4901e4..0e315f8 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRatingPushNotificationViewController.m @@ -267,7 +267,7 @@ - (void)initialiseViewHierarchy { richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; UILabel *richSubLabel = [[UILabel alloc] init]; - richSubLabel.attributedText = [self.viewController getHtmlParsedString:richSub isTitle:NO bckColor:colorHex]; + richSubLabel.attributedText = [self.viewController getHtmlParsedString:richSub isTitle:YES bckColor:colorHex]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; UILabel *richBodyLabel = [[UILabel alloc] init]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index d0ec7e8..2eef958 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -252,8 +252,17 @@ - (NSTextAlignment)naturalTextAligmentForText:(NSString*)text { } - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL)isTitle bckColor:(NSString *)bckColor { + BOOL containsHTML = [self containsHTML:textString]; + NSString *inputString = textString; + + // Updating font attributes overrides Italic characteristic + // Adding extra tags makes more sense + if (containsHTML && isTitle) { + inputString = [NSString stringWithFormat: @"%@", textString]; + } + NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] - initWithData: [textString dataUsingEncoding:NSUnicodeStringEncoding] + initWithData: [inputString dataUsingEncoding:NSUnicodeStringEncoding] options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes: nil error: nil @@ -264,20 +273,18 @@ - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL [attributedString updateDefaultTextColor]; } - BOOL containsHTML = [self containsHTML:textString]; - BOOL containsFontSize = [textString rangeOfString:@"font-size"].location != NSNotFound; - BOOL containsStrong = [textString rangeOfString:@""].location != NSNotFound; - + BOOL containsFontSize = [inputString rangeOfString:@"font-size"].location != NSNotFound; + UIFont *defaultFont = [UIFont systemFontOfSize:[UIFont labelFontSize]]; UIFont *boldFont = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; /* If html string doesn't contain font-size, - then setting default based on Strong tag or title position + then setting default based on title position */ if (containsHTML && containsFontSize == NO) { - if (containsStrong) { + if (isTitle) { [attributedString setFontFaceWithFont:boldFont]; } else { [attributedString setFontFaceWithFont:defaultFont]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m index 4b5ddef..fd519f4 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXTextPushNotificationViewController.m @@ -77,7 +77,7 @@ - (void)setupLabelsContainer { richTitleLabel.textAlignment = [self.viewController naturalTextAligmentForText:richTitleLabel.text]; UILabel *richSubLabel = [[UILabel alloc] init]; - richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:NO bckColor:colorHex]; + richSubLabel.attributedText = [self.viewController getHtmlParsedString:subtitle isTitle:YES bckColor:colorHex]; richSubLabel.textAlignment = [self.viewController naturalTextAligmentForText:richSubLabel.text]; UILabel *richBodyLabel = [[UILabel alloc] init]; From 1e0d57f8c0df8007308d98f7b8ad2da493c96895 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Thu, 10 Mar 2022 20:12:36 +0530 Subject: [PATCH 27/28] Dark mode issue resolved caused by traitCollection update issue --- .../NSMutableAttributedString+Additions.m | 10 ++++------ .../WEXRichPushNotificationViewController.m | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m index 51f388f..531bb60 100644 --- a/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m +++ b/WebEngageAppEx/Classes/ContentExtension/NSMutableAttributedString+Additions.m @@ -23,11 +23,9 @@ - (void)updateDefaultTextColor { UIColor *labelColor = [UIColor WEXLabelColor]; NSString *colorHex = [self hexStringFromColor:color]; - if (UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { - if ([colorHex isEqualToString:@"#000000"]) { - [self removeAttribute:NSForegroundColorAttributeName range:range]; - [self addAttribute:NSForegroundColorAttributeName value:labelColor range:range]; - } + if ([colorHex isEqualToString:@"000000"]) { + [self removeAttribute:NSForegroundColorAttributeName range:range]; + [self addAttribute:NSForegroundColorAttributeName value:labelColor range:range]; } }]; [self endEditing]; @@ -41,7 +39,7 @@ - (NSString *)hexStringFromColor:(UIColor *)color { CGFloat g = components[1]; CGFloat b = components[2]; - return [NSString stringWithFormat:@"#%02lX%02lX%02lX", + return [NSString stringWithFormat:@"%02lX%02lX%02lX", lroundf(r * 255), lroundf(g * 255), lroundf(b * 255)]; diff --git a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m index 2eef958..3712cad 100644 --- a/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m +++ b/WebEngageAppEx/Classes/ContentExtension/WEXRichPushNotificationViewController.m @@ -27,6 +27,7 @@ @interface WEXRichPushNotificationViewController () @property (nonatomic) NSUserDefaults *richPushDefaults; @property (atomic) BOOL isRendering; +@property (atomic) BOOL isDarkMode; #endif @@ -87,6 +88,7 @@ - (void)didReceiveNotification:(UNNotification *)notification API_AVAILABLE(ios self.notification = notification; self.isRendering = YES; + [self updateDarkModeStatus]; NSString *appGroup = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"WEX_APP_GROUP"]; @@ -141,6 +143,10 @@ - (void)didReceiveNotificationResponse:(UNNotificationResponse *)response comple [self.currentLayout didReceiveNotificationResponse:response completionHandler:completion]; } +- (void)traitCollectionDidChange: (UITraitCollection *) previousTraitCollection { + [super traitCollectionDidChange: previousTraitCollection]; + [self updateDarkModeStatus]; +} - (NSMutableDictionary *) getActivityDictionaryForCurrentNotification { @@ -269,7 +275,7 @@ - (NSAttributedString *)getHtmlParsedString:(NSString *)textString isTitle:(BOOL ]; BOOL hasBckColor = bckColor && ![bckColor isEqualToString:@""]; - if (!hasBckColor) { + if (!hasBckColor && _isDarkMode) { [attributedString updateDefaultTextColor]; } @@ -311,6 +317,16 @@ - (BOOL)containsHTML:(NSString *)value { return [htmlText evaluateWithObject:value]; } +- (void)updateDarkModeStatus { + if (@available(iOS 12.0, *)) { + if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { + self.isDarkMode = YES; + return; + } + } + self.isDarkMode = NO; +} + #endif @end From c1c130c87f80e1f0cf9b5b1ad01f74fd31b67781 Mon Sep 17 00:00:00 2001 From: Unmesh Rathod Date: Thu, 10 Mar 2022 20:43:58 +0530 Subject: [PATCH 28/28] Release 1.0.0 --- WebEngageAppEx.podspec | 4 ++-- WebEngageBannerPush.podspec | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/WebEngageAppEx.podspec b/WebEngageAppEx.podspec index 527c4e2..46bf928 100644 --- a/WebEngageAppEx.podspec +++ b/WebEngageAppEx.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |spec| spec.name = 'WebEngageAppEx' - spec.version = '0.12.0' + spec.version = '1.0.0' spec.summary = 'App Extension Target SDK for WebEngage for Rich Push Notifications support.' @@ -10,7 +10,7 @@ Pod::Spec.new do |spec| DESC spec.license = 'MIT' - spec.author = 'Saumitra Bhave', 'Uzma Sayyed', 'Unmesh Rathod' + spec.author = 'Saumitra Bhave', 'Uzma Sayyed', 'Unmesh Rathod', 'Bhavesh Sarwar' spec.homepage = 'https://webengage.com' spec.social_media_url = 'http://twitter.com/webengage' spec.documentation_url = 'https://docs.webengage.com/docs/ios-getting-started' diff --git a/WebEngageBannerPush.podspec b/WebEngageBannerPush.podspec index 812a8c5..d9d22c1 100644 --- a/WebEngageBannerPush.podspec +++ b/WebEngageBannerPush.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |spec| spec.name = 'WebEngageBannerPush' - spec.version = '0.12.0' + spec.version = '1.0.0' spec.summary = 'Extension Target SDK for adding WebEngage Rich Push Notifications support' spec.description = <<-DESC @@ -9,7 +9,7 @@ Pod::Spec.new do |spec| DESC spec.license = 'MIT' - spec.author = 'Saumitra Bhave', 'Uzma Sayyed', 'Unmesh Rathod' + spec.author = 'Saumitra Bhave', 'Uzma Sayyed', 'Unmesh Rathod', 'Bhavesh Sarwar' spec.homepage = 'https://webengage.com' spec.social_media_url = 'http://twitter.com/webengage' spec.documentation_url = 'https://docs.webengage.com/docs/ios-getting-started'