From 4f02c1971d6fc3b179eae50c47a258ac38d1897a Mon Sep 17 00:00:00 2001 From: Shubham Naidu Date: Thu, 8 Aug 2024 10:19:04 +0530 Subject: [PATCH 1/5] removed extra check for bckColor as this field is missing in Test InAPP. --- Sources/WEContentExtension/Common/WEConstants.swift | 2 +- .../Layouts/Banner/BannerLayoutRenderer.swift | 2 +- .../Layouts/Carousel/CarouselLayoutRenderer.swift | 6 +++--- .../WEXCarouselPushNotificationViewController.swift | 2 +- .../Layouts/Overlay/OverlayLayoutRenderer.swift | 2 +- .../Layouts/Rating/RatingLayoutRenderer.swift | 2 +- .../Layouts/Text/TextLayoutRenderer.swift | 3 ++- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Sources/WEContentExtension/Common/WEConstants.swift b/Sources/WEContentExtension/Common/WEConstants.swift index 60eac10..dcb3836 100644 --- a/Sources/WEContentExtension/Common/WEConstants.swift +++ b/Sources/WEContentExtension/Common/WEConstants.swift @@ -13,7 +13,7 @@ struct WEConstants{ static let BIG_PICTURE = "BIG_PICTURE" static let BIG_TEXT = "BIG_TEXT" static let OVERLAY = "OVERLAY" - static let BLACKCOLOR = "bckColor" + static let BACKCOLOR = "bckColor" static let CAROUSEL = "CAROUSEL_V1" static let COLLAPSED = "collapsed" static let CONTENT_PADDING: CGFloat = 10.0 diff --git a/Sources/WEContentExtension/Layouts/Banner/BannerLayoutRenderer.swift b/Sources/WEContentExtension/Layouts/Banner/BannerLayoutRenderer.swift index 4fb3c37..7779666 100644 --- a/Sources/WEContentExtension/Layouts/Banner/BannerLayoutRenderer.swift +++ b/Sources/WEContentExtension/Layouts/Banner/BannerLayoutRenderer.swift @@ -56,7 +56,7 @@ extension WEXBannerPushNotificationViewController{ /// Sets up the container for rich content labels based on the expandable details of the notification. func setupLabelsContainer() { if let superViewWrapper = view?.subviews.first, - let expandableDetails = notification?.request.content.userInfo[WEConstants.EXPANDABLEDETAILS] as? [String: Any], let colorHex = expandableDetails[WEConstants.BLACKCOLOR] as? String{ + let expandableDetails = notification?.request.content.userInfo[WEConstants.EXPANDABLEDETAILS] as? [String: Any], let colorHex = expandableDetails[WEConstants.BACKCOLOR] as? String{ let richContentView = UIView() if #available(iOS 13.0, *) { richContentView.backgroundColor = UIColor.colorFromHexString(colorHex, defaultColor: UIColor.WEXWhiteColor()) diff --git a/Sources/WEContentExtension/Layouts/Carousel/CarouselLayoutRenderer.swift b/Sources/WEContentExtension/Layouts/Carousel/CarouselLayoutRenderer.swift index 653f04f..6009dfd 100644 --- a/Sources/WEContentExtension/Layouts/Carousel/CarouselLayoutRenderer.swift +++ b/Sources/WEContentExtension/Layouts/Carousel/CarouselLayoutRenderer.swift @@ -29,7 +29,7 @@ extension WEXCarouselPushNotificationViewController{ var superViewHeight = viewHeight + 2 * verticalMargins if let expandableDetails = notification.request.content.userInfo[WEConstants.EXPANDABLEDETAILS] as? [String : Any]{ - if let colorHex = expandableDetails[WEConstants.BLACKCOLOR] as? String{ + if let colorHex = expandableDetails[WEConstants.BACKCOLOR] as? String{ if #available(iOS 13.0, *) { self.view?.backgroundColor = UIColor.colorFromHexString(colorHex, defaultColor: UIColor.WEXWhiteColor()) } @@ -85,7 +85,7 @@ extension WEXCarouselPushNotificationViewController{ } let bottomSeparator = UIView(frame: CGRect(x: 0.0, y: CGFloat(superViewHeight) - 0.5, width: superViewWidth, height: 0.5)) - if let colorHex = expandableDetails[WEConstants.BLACKCOLOR] as? String{ + if let colorHex = expandableDetails[WEConstants.BACKCOLOR] as? String{ if #available(iOS 13.0, *) { bottomSeparator.backgroundColor = UIColor.colorFromHexString(colorHex, defaultColor: UIColor.WEXGreyColor()) }} @@ -124,7 +124,7 @@ extension WEXCarouselPushNotificationViewController{ richMessage = self.notification?.request.content.body } - let colorHex = expandableDetails[WEConstants.BLACKCOLOR] as? String + let colorHex = expandableDetails[WEConstants.BACKCOLOR] as? String let richTitleLabel = UILabel() if let richTitle = richTitle{ diff --git a/Sources/WEContentExtension/Layouts/Carousel/WEXCarouselPushNotificationViewController.swift b/Sources/WEContentExtension/Layouts/Carousel/WEXCarouselPushNotificationViewController.swift index 1231a1f..07ebd38 100644 --- a/Sources/WEContentExtension/Layouts/Carousel/WEXCarouselPushNotificationViewController.swift +++ b/Sources/WEContentExtension/Layouts/Carousel/WEXCarouselPushNotificationViewController.swift @@ -236,7 +236,7 @@ class WEXCarouselPushNotificationViewController: WEXRichPushLayout { viewHeight = viewWidth * WEConstants.LANDSCAPE_ASPECT } let expandableDetails = notification?.request.content.userInfo[WEConstants.EXPANDABLEDETAILS] as? [String: Any] - let colorHex = expandableDetails?[WEConstants.BLACKCOLOR] as? String ?? "" + let colorHex = expandableDetails?[WEConstants.BACKCOLOR] as? String ?? "" if #available(iOS 13.0, *) { viewToReturn.backgroundColor = UIColor.colorFromHexString(colorHex, defaultColor: UIColor.WEXGreyColor()) } diff --git a/Sources/WEContentExtension/Layouts/Overlay/OverlayLayoutRenderer.swift b/Sources/WEContentExtension/Layouts/Overlay/OverlayLayoutRenderer.swift index 5d00112..672fcc1 100644 --- a/Sources/WEContentExtension/Layouts/Overlay/OverlayLayoutRenderer.swift +++ b/Sources/WEContentExtension/Layouts/Overlay/OverlayLayoutRenderer.swift @@ -56,7 +56,7 @@ extension WEXOverlayPushNotificationViewController{ /// Sets up the container for rich content labels based on the expandable details of the notification. func setupLabelsContainer() { if let superViewWrapper = view?.subviews.first, - let expandableDetails = notification?.request.content.userInfo[WEConstants.EXPANDABLEDETAILS] as? [String: Any], let colorHex = expandableDetails[WEConstants.BLACKCOLOR] as? String{ + let expandableDetails = notification?.request.content.userInfo[WEConstants.EXPANDABLEDETAILS] as? [String: Any], let colorHex = expandableDetails[WEConstants.BACKCOLOR] as? String{ let richContentView = UIView() if #available(iOS 13.0, *) { richContentView.backgroundColor = UIColor.clear diff --git a/Sources/WEContentExtension/Layouts/Rating/RatingLayoutRenderer.swift b/Sources/WEContentExtension/Layouts/Rating/RatingLayoutRenderer.swift index 4885ace..2513ace 100644 --- a/Sources/WEContentExtension/Layouts/Rating/RatingLayoutRenderer.swift +++ b/Sources/WEContentExtension/Layouts/Rating/RatingLayoutRenderer.swift @@ -158,7 +158,7 @@ extension WEXRatingPushNotificationViewController{ richMessage = self.notification?.request.content.body } - let colorHex = expandableDetails?[WEConstants.BLACKCOLOR] as? String + let colorHex = expandableDetails?[WEConstants.BACKCOLOR] as? String // Add a notification content view for displaying title and body. let richContentView = UIView() diff --git a/Sources/WEContentExtension/Layouts/Text/TextLayoutRenderer.swift b/Sources/WEContentExtension/Layouts/Text/TextLayoutRenderer.swift index 9d8a480..db7817a 100644 --- a/Sources/WEContentExtension/Layouts/Text/TextLayoutRenderer.swift +++ b/Sources/WEContentExtension/Layouts/Text/TextLayoutRenderer.swift @@ -13,8 +13,9 @@ extension WEXTextPushNotificationViewController { /// Sets up the container for rich content labels based on the expandable details of the notification. func setupLabelsContainer() { if let superViewWrapper = view?.subviews.first, - let expandableDetails = notification?.request.content.userInfo[WEConstants.EXPANDABLEDETAILS] as? [String: Any], let colorHex = expandableDetails[WEConstants.BLACKCOLOR] as? String{ + let expandableDetails = notification?.request.content.userInfo[WEConstants.EXPANDABLEDETAILS] as? [String: Any]{ let richContentView = UIView() + let colorHex = (expandableDetails[WEConstants.EXPANDABLEDETAILS] as? String) ?? "" if #available(iOS 13.0, *) { richContentView.backgroundColor = UIColor.colorFromHexString(colorHex, defaultColor: UIColor.WEXWhiteColor()) } From d66627732489ae7d8af2ee5c7e639cfeeb24e605 Mon Sep 17 00:00:00 2001 From: Shubham Naidu Date: Thu, 26 Sep 2024 09:32:56 +0530 Subject: [PATCH 2/5] added attributed text after checking alignemnt --- .../Common/CoreApi/WEXCoreUtils.swift | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift b/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift index 00d9c47..dc65f78 100644 --- a/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift +++ b/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift @@ -14,36 +14,22 @@ struct WEXCoreUtils { guard let message = message else { return nil } - guard let attributedString = viewController?.getHtmlParsedString(message, isTitle: false, bckColor: colorHex) else { return nil } - + let finalAttributedString = NSMutableAttributedString(attributedString: attributedString) let rawString = attributedString.string - let lines = rawString.components(separatedBy: "\n") - let finalAttributedString = NSMutableAttributedString() - - for line in lines { - if !line.isEmpty { - guard let alignment = viewController?.naturalTextAlignmentForText(line, forDescription: true) else { - continue - } - - let paragraphStyle = NSMutableParagraphStyle() - paragraphStyle.alignment = alignment - - let attributes: [NSAttributedString.Key: Any] = [ - .paragraphStyle: paragraphStyle - ] + let paragraphRanges = rawString.paragraphRanges() - let attributedLine = NSAttributedString(string: line, attributes: attributes) - finalAttributedString.append(attributedLine) - if line != lines.last { - finalAttributedString.append(NSAttributedString(string: "\n")) - } + for range in paragraphRanges { + let paragraphText = (rawString as NSString).substring(with: range) + guard let alignment = viewController?.naturalTextAlignmentForText(paragraphText, forDescription: true) else { + continue } + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.alignment = alignment + finalAttributedString.addAttribute(.paragraphStyle, value: paragraphStyle, range: range) } - return finalAttributedString } @@ -115,3 +101,22 @@ extension Character { return unicodeScalars.count == 1 && emojiRange.contains(unicodeScalars.first!) } } + +extension String { + func paragraphRanges() -> [NSRange] { + let nsString = self as NSString + var ranges: [NSRange] = [] + var paragraphStart = 0 + var paragraphEnd = 0 + var contentsEnd = 0 + + let length = nsString.length + while paragraphStart < length { + nsString.getParagraphStart(¶graphStart, end: ¶graphEnd, contentsEnd: &contentsEnd, for: NSMakeRange(paragraphStart, 0)) + ranges.append(NSMakeRange(paragraphStart, contentsEnd - paragraphStart)) + paragraphStart = paragraphEnd + } + + return ranges + } +} From 1292bea3f1debe0113f834f14254c8a92c31a3ec Mon Sep 17 00:00:00 2001 From: Shubham Naidu Date: Fri, 18 Oct 2024 09:25:56 +0530 Subject: [PATCH 3/5] added logs for App group configuration check --- .../Common/CoreApi/WEXCoreUtils.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift b/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift index 00d9c47..ea24bd6 100644 --- a/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift +++ b/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift @@ -69,13 +69,18 @@ struct WEXCoreUtils { let bundleIdentifier = bundle.object(forInfoDictionaryKey: WEConstants.CFBUNDLEIDENTIFIER) as? String appGroup = "\(WEConstants.GROUP).\(bundleIdentifier ?? "").\(WEConstants.WENOTIFICATIONGROUP)" } + + + if let appGroupUrl = appGroup, let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupUrl) { + print("WebEngage App Group configured in Content Extension") + } else { + ALog("WebEngage App Group not configured in Content Extension") + } if let defaults = UserDefaults(suiteName: appGroup) { return defaults - } else { - print("Shared User Defaults could not be initialized. Ensure Shared App Groups have been enabled on Main App & Notification Service Extension Targets.") - fatalError("Shared User Defaults initialization failed.") } + return nil } // Checks if a given string contains HTML tags using regular expressions. @@ -90,6 +95,9 @@ struct WEXCoreUtils { sharedDefaults.synchronize() } } + static func ALog(_ message: String, file: String = #file, function: String = #function, line: Int = #line) { + NSLog("%@ [Line %d] ERROR: %@", (function as NSString).lastPathComponent, line, message) + } } From 2834296cecaccc0f3fec8ac1407a167242a6020c Mon Sep 17 00:00:00 2001 From: Milind Keni Date: Wed, 20 Nov 2024 10:46:17 +0530 Subject: [PATCH 4/5] version number change to 1.1.2 --- Sources/WEContentExtension/Common/WEConstants.swift | 2 +- WEContentExtension.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WEContentExtension/Common/WEConstants.swift b/Sources/WEContentExtension/Common/WEConstants.swift index dcb3836..27b9b21 100644 --- a/Sources/WEContentExtension/Common/WEConstants.swift +++ b/Sources/WEContentExtension/Common/WEConstants.swift @@ -44,7 +44,7 @@ struct WEConstants{ static let WENOTIFICATIONGROUP = "WEGNotificationGroup" static let WEBENGAGE = "webengage" static let WEX_APP_GROUP = "WEX_APP_GROUP" - static let WEX_CONTENT_EXTENSION_VERSION = "1.1.1" + static let WEX_CONTENT_EXTENSION_VERSION = "1.1.2" static let WEX_CONTENT_EXTENSION_VERSION_STRING = "WEContentExtension_version" static let WHITECOLOR = "#FFFFFF" } diff --git a/WEContentExtension.podspec b/WEContentExtension.podspec index 6886e54..25e9582 100644 --- a/WEContentExtension.podspec +++ b/WEContentExtension.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'WEContentExtension' - s.version = '1.1.1' + s.version = '1.1.2' s.summary = 'Extension Target SDK for adding WebEngage Rich Push Notifications support' s.description = <<-DESC From 44a9d47c63864a11a91a83fb26d53cdb9e359323 Mon Sep 17 00:00:00 2001 From: Milind Keni Date: Wed, 20 Nov 2024 10:52:41 +0530 Subject: [PATCH 5/5] 'containerURL' was never used replacing with '_' --- Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift b/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift index 43a096e..7c5c4ff 100644 --- a/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift +++ b/Sources/WEContentExtension/Common/CoreApi/WEXCoreUtils.swift @@ -57,7 +57,7 @@ struct WEXCoreUtils { } - if let appGroupUrl = appGroup, let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupUrl) { + if let appGroupUrl = appGroup, let _ = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupUrl) { print("WebEngage App Group configured in Content Extension") } else { ALog("WebEngage App Group not configured in Content Extension")