From 6f623ceabec49b86690b91e87b40448df5c314a7 Mon Sep 17 00:00:00 2001 From: Helder Pinhal Date: Fri, 7 Oct 2022 10:46:58 +0100 Subject: [PATCH 1/4] feat(core): add flag for preserving notification categories --- NotificareKit/Sources/NotificareOptions.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NotificareKit/Sources/NotificareOptions.swift b/NotificareKit/Sources/NotificareOptions.swift index 50d25511..052b542c 100644 --- a/NotificareKit/Sources/NotificareOptions.swift +++ b/NotificareKit/Sources/NotificareOptions.swift @@ -12,6 +12,7 @@ public struct NotificareOptions: Decodable { public static let DEFAULT_AUTO_CONFIG = true public static let DEFAULT_SWIZZLING_ENABLED = true public static let DEFAULT_USER_NOTIFICATION_CENTER_DELEGATE_ENABLED = true + public static let DEFAULT_PRESERVE_EXISTING_NOTIFICATION_CATEGORIES = false public static let DEFAULT_CRASH_REPORTS_ENABLED = true public static let DEFAULT_HEADING_API_ENABLED = false public static let DEFAULT_VISITS_API_ENABLED = false @@ -22,6 +23,7 @@ public struct NotificareOptions: Decodable { public let autoConfig: Bool public let swizzlingEnabled: Bool public let userNotificationCenterDelegateEnabled: Bool + public let preserveExistingNotificationCategories: Bool public let crashReportsEnabled: Bool public let headingApiEnabled: Bool public let visitsApiEnabled: Bool @@ -37,6 +39,7 @@ public struct NotificareOptions: Decodable { autoConfig: Bool = DEFAULT_AUTO_CONFIG, swizzlingEnabled: Bool = DEFAULT_SWIZZLING_ENABLED, userNotificationCenterDelegateEnabled: Bool = DEFAULT_USER_NOTIFICATION_CENTER_DELEGATE_ENABLED, + preserveExistingNotificationCategories: Bool = DEFAULT_PRESERVE_EXISTING_NOTIFICATION_CATEGORIES, crashReportsEnabled: Bool = DEFAULT_CRASH_REPORTS_ENABLED, headingApiEnabled: Bool = DEFAULT_HEADING_API_ENABLED, visitsApiEnabled: Bool = DEFAULT_VISITS_API_ENABLED, @@ -51,6 +54,7 @@ public struct NotificareOptions: Decodable { self.autoConfig = autoConfig self.swizzlingEnabled = swizzlingEnabled self.userNotificationCenterDelegateEnabled = userNotificationCenterDelegateEnabled + self.preserveExistingNotificationCategories = preserveExistingNotificationCategories self.crashReportsEnabled = crashReportsEnabled self.headingApiEnabled = headingApiEnabled self.visitsApiEnabled = visitsApiEnabled @@ -110,6 +114,7 @@ public extension NotificareOptions { autoConfig = decoded.autoConfig swizzlingEnabled = decoded.swizzlingEnabled userNotificationCenterDelegateEnabled = decoded.userNotificationCenterDelegateEnabled + preserveExistingNotificationCategories = decoded.preserveExistingNotificationCategories crashReportsEnabled = decoded.crashReportsEnabled headingApiEnabled = decoded.headingApiEnabled visitsApiEnabled = decoded.visitsApiEnabled @@ -132,6 +137,7 @@ public extension NotificareOptions { case autoConfig = "AUTO_CONFIG" case swizzlingEnabled = "SWIZZLING_ENABLED" case userNotificationCenterDelegateEnabled = "USER_NOTIFICATION_CENTER_DELEGATE_ENABLED" + case preserveExistingNotificationCategories = "PRESERVE_EXISTING_NOTIFICATION_CATEGORIES" case crashReportsEnabled = "CRASH_REPORTING_ENABLED" case headingApiEnabled = "HEADING_API_ENABLED" case visitsApiEnabled = "VISITS_API_ENABLED" @@ -150,6 +156,7 @@ public extension NotificareOptions { autoConfig = try container.decodeIfPresent(Bool.self, forKey: .autoConfig) ?? NotificareOptions.DEFAULT_AUTO_CONFIG swizzlingEnabled = try container.decodeIfPresent(Bool.self, forKey: .swizzlingEnabled) ?? NotificareOptions.DEFAULT_SWIZZLING_ENABLED userNotificationCenterDelegateEnabled = try container.decodeIfPresent(Bool.self, forKey: .userNotificationCenterDelegateEnabled) ?? NotificareOptions.DEFAULT_USER_NOTIFICATION_CENTER_DELEGATE_ENABLED + preserveExistingNotificationCategories = try container.decodeIfPresent(Bool.self, forKey: .preserveExistingNotificationCategories) ?? NotificareOptions.DEFAULT_PRESERVE_EXISTING_NOTIFICATION_CATEGORIES crashReportsEnabled = try container.decodeIfPresent(Bool.self, forKey: .crashReportsEnabled) ?? NotificareOptions.DEFAULT_CRASH_REPORTS_ENABLED headingApiEnabled = try container.decodeIfPresent(Bool.self, forKey: .headingApiEnabled) ?? NotificareOptions.DEFAULT_HEADING_API_ENABLED visitsApiEnabled = try container.decodeIfPresent(Bool.self, forKey: .visitsApiEnabled) ?? NotificareOptions.DEFAULT_VISITS_API_ENABLED From 6936d4072e52e9ac449f91c91574890f94b2e92c Mon Sep 17 00:00:00 2001 From: Helder Pinhal Date: Fri, 7 Oct 2022 10:48:17 +0100 Subject: [PATCH 2/4] feat(push): respect flag for preserving existing notification categories --- ...ficarePushImpl+UIApplicationDelegate.swift | 5 +- .../Internals/NotificarePushImpl.swift | 72 +++++++++++-------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/NotificarePushKit/Sources/Internals/NotificarePushImpl+UIApplicationDelegate.swift b/NotificarePushKit/Sources/Internals/NotificarePushImpl+UIApplicationDelegate.swift index 16feea87..b13b02a9 100644 --- a/NotificarePushKit/Sources/Internals/NotificarePushImpl+UIApplicationDelegate.swift +++ b/NotificarePushKit/Sources/Internals/NotificarePushImpl+UIApplicationDelegate.swift @@ -65,8 +65,9 @@ extension NotificarePushImpl: NotificareAppDelegateInterceptor { Notificare.shared.fetchApplication { result in switch result { case .success: - self.reloadActionCategories() - completion(.success(())) + self.reloadActionCategories { + completion(.success(())) + } case .failure: completion(.success(())) diff --git a/NotificarePushKit/Sources/Internals/NotificarePushImpl.swift b/NotificarePushKit/Sources/Internals/NotificarePushImpl.swift index 7bb9b0d2..646b69a5 100644 --- a/NotificarePushKit/Sources/Internals/NotificarePushImpl.swift +++ b/NotificarePushKit/Sources/Internals/NotificarePushImpl.swift @@ -90,33 +90,13 @@ internal class NotificarePushImpl: NSObject, NotificareModule, NotificarePush { NotificareLogger.info("Registered user notification settings.") if granted { - NotificareLogger.info("User granted permission to receive alerts, badge and sounds") - self.reloadActionCategories() + NotificareLogger.info("User granted permission to receive alerts, badge and sounds.") + self.reloadActionCategories { + self.handleEnabledRemoteNotifications(granted, completion) + } } else { NotificareLogger.info("User did not grant permission to receive alerts, badge and sounds.") - } - - self.handleNotificationSettings(granted) { result in - switch result { - case .success: - if granted, LocalStorage.firstRegistration { - Notificare.shared.events().logPushRegistration { result in - switch result { - case .success: - LocalStorage.firstRegistration = false - completion(.success(granted)) - case let .failure(error): - completion(.failure(error)) - } - } - - return - } - - completion(.success(granted)) - case let .failure(error): - completion(.failure(error)) - } + self.handleEnabledRemoteNotifications(granted, completion) } } @@ -201,11 +181,22 @@ internal class NotificarePushImpl: NSObject, NotificareModule, NotificarePush { // MARK: Internal API - internal func reloadActionCategories() { + internal func reloadActionCategories(_ completion: @escaping () -> Void) { NotificareLogger.debug("Reloading action categories.") - let categories = loadAvailableCategories() - notificationCenter.setNotificationCategories(categories) + if Notificare.shared.options?.preserveExistingNotificationCategories == true { + notificationCenter.getNotificationCategories { existingCategories in + let categories = existingCategories.union(self.loadAvailableCategories()) + self.notificationCenter.setNotificationCategories(categories) + + completion() + } + } else { + let categories = loadAvailableCategories() + notificationCenter.setNotificationCategories(categories) + + completion() + } } private func loadAvailableCategories() -> Set { @@ -387,6 +378,31 @@ internal class NotificarePushImpl: NSObject, NotificareModule, NotificarePush { } } + private func handleEnabledRemoteNotifications(_ granted: Bool, _ completion: @escaping NotificareCallback) { + handleNotificationSettings(granted) { result in + switch result { + case .success: + if granted, LocalStorage.firstRegistration { + Notificare.shared.events().logPushRegistration { result in + switch result { + case .success: + LocalStorage.firstRegistration = false + completion(.success(granted)) + case let .failure(error): + completion(.failure(error)) + } + } + + return + } + + completion(.success(granted)) + case let .failure(error): + completion(.failure(error)) + } + } + } + private func fetchAttachment(for request: UNNotificationRequest, _ completion: @escaping NotificareCallback) { guard let attachment = request.content.userInfo["attachment"] as? [String: Any], let uri = attachment["uri"] as? String From fd60f7771894bf51543813fc243da2c183c51b45 Mon Sep 17 00:00:00 2001 From: Helder Pinhal Date: Fri, 7 Oct 2022 11:38:25 +0100 Subject: [PATCH 3/4] chore: update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb6da988..f683673e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 3.4.0-beta.3 + +- Add option to preserve existing notification categories + ## 3.4.0-beta.2 - Fix in-app message action click event From 335d29655271f331105f9e80d631ee4868702dc4 Mon Sep 17 00:00:00 2001 From: Helder Pinhal Date: Fri, 7 Oct 2022 11:46:42 +0100 Subject: [PATCH 4/4] chore: update package.swift & podspec --- Notificare.podspec | 2 +- Package.swift | 48 +++++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Notificare.podspec b/Notificare.podspec index a36d669b..ad7d4be4 100644 --- a/Notificare.podspec +++ b/Notificare.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "Notificare" - spec.version = "3.4.0-beta.2" + spec.version = "3.4.0-beta.3" spec.summary = "Notificare Library for iOS apps" spec.description = <<-DESC The Notificare iOS Library implements the power of smart notifications, location services, contextual marketing and powerful loyalty solutions provided by the Notificare platform in iOS applications. diff --git a/Package.swift b/Package.swift index 616a14be..78139fb2 100644 --- a/Package.swift +++ b/Package.swift @@ -60,63 +60,63 @@ let package = Package( targets: [ .binaryTarget( name: "NotificareKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare.zip", - checksum: "bf6e418cb4c8a3c4a3c3839ffbc2cab356aa70ee8474c7ff38b059634af17481" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare.zip", + checksum: "c04465c16bbc299bdc67dc64910a5c47f689b3102661ed1b0eb89c6382ee323b" ), .binaryTarget( name: "NotificareAssetsKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-assets.zip", - checksum: "825f361b5d2a62221936698ac968106901db3198bf8bc9420755c2b05bdfec8b" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-assets.zip", + checksum: "e730fc9df923154e61de3a614f1be1babb2030373e79c4e7ea117612b27ecb5c" ), .binaryTarget( name: "NotificareAuthenticationKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-authentication.zip", - checksum: "4bf035bc9c7611ddbbbf9b7905ad0193a9d3b90c67d23fc353a51e4f894dbc23" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-authentication.zip", + checksum: "7c97d8c27453b38e87b7a4e7d4cf162dbde961ade778709b55ac08c9dda360ef" ), .binaryTarget( name: "NotificareGeoKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-geo.zip", - checksum: "87e35b2379699fc91e39f94f731511ac1f1d5b727df95d391ccec7336653b376" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-geo.zip", + checksum: "d4cfc29b86aa32abdd8590cfccd0a7cd77e3e3b0c8f2248f62107e3a8e6d7f82" ), .binaryTarget( name: "NotificareInAppMessagingKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-in-app-messaging.zip", - checksum: "9b3be03817fed697f2e51e0100fee73128c32c16b12561bbab4762c6e15316a0" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-in-app-messaging.zip", + checksum: "b549d3abd62c0f89f5fc21927b980a7b19187336a0082d34faa52c69d5afe8b9" ), .binaryTarget( name: "NotificareInboxKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-inbox.zip", - checksum: "4614151d2ee9d824f0db2550e4de70e2a4dbf1829202c103c309258e4f29b7bc" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-inbox.zip", + checksum: "bce55031102ee5601738358ebb7c29cbed47e11a390bf125841e5a1df2f90df9" ), .binaryTarget( name: "NotificareLoyaltyKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-loyalty.zip", - checksum: "3855228590e06993f5ad0cedd0fe0cd3dca591abd0b1ca0fc344f650e54a65a4" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-loyalty.zip", + checksum: "c2faf3a3786822284a299dc7c119b2a0306e19e52589b6c4478f776586bab73e" ), .binaryTarget( name: "NotificareMonetizeKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-monetize.zip", - checksum: "5f918b965a8cadd90f8d7f0ca9d9d1504381934196537bf83cc4035527dfcaf6" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-monetize.zip", + checksum: "1488d3d6b283eaccacf5447de15366f81aaca6a5792646a60139a6c01aab450e" ), .binaryTarget( name: "NotificarePushKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-push.zip", - checksum: "c9aa3a6559aa6174f78ca2860e1c0c8620376c3c5ce303624cac8c096610ecf6" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-push.zip", + checksum: "5d92ef65c0b6e1d518dbf218e95929ad6b83c7f4ec903d8d58e954da7787901b" ), .binaryTarget( name: "NotificareNotificationServiceExtensionKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-notification-service-extension.zip", - checksum: "44dd2964ebc54fd7a52bba0ce95093ae6caf68e6ce50a2e1171b55269a6630e6" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-notification-service-extension.zip", + checksum: "e63d6e33f4931a1d459f012b2efcc595948ca80c7c713e5b9576adfafeb32598" ), .binaryTarget( name: "NotificarePushUIKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-push-ui.zip", - checksum: "af25788a1008f731bedf1c3abec2f84508d686e80a44fadab45021d7347d5166" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-push-ui.zip", + checksum: "2a16915f93a40e40dd2a72a7ff54282945dd9f1e0b8052c232a7acb66326d7a1" ), .binaryTarget( name: "NotificareScannablesKit", - url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.2/spm-notificare-scannables.zip", - checksum: "7d0ae84cf036e7e0243f871abce2f8a604bbc8a5e4a21b641296fb51c07557b6" + url: "https://github.com/notificare/notificare-sdk-ios/releases/download/3.4.0-beta.3/spm-notificare-scannables.zip", + checksum: "d3fb054f0edbc6ac653adbeac565afff1efb57e3b7fbf582329fb4def9955a52" ), ] )