Skip to content

Commit

Permalink
Merge pull request #35 from Notificare/release/3.4.0-beta.3
Browse files Browse the repository at this point in the history
3.4.0-beta.3
  • Loading branch information
hpinhal authored Oct 7, 2022
2 parents 1cfe7ae + 335d296 commit 01ecc69
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Notificare.podspec
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 7 additions & 0 deletions NotificareKit/Sources/NotificareOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(()))
Expand Down
72 changes: 44 additions & 28 deletions NotificarePushKit/Sources/Internals/NotificarePushImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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<UNNotificationCategory> {
Expand Down Expand Up @@ -387,6 +378,31 @@ internal class NotificarePushImpl: NSObject, NotificareModule, NotificarePush {
}
}

private func handleEnabledRemoteNotifications(_ granted: Bool, _ completion: @escaping NotificareCallback<Bool>) {
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<UNNotificationAttachment>) {
guard let attachment = request.content.userInfo["attachment"] as? [String: Any],
let uri = attachment["uri"] as? String
Expand Down
48 changes: 24 additions & 24 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
]
)

0 comments on commit 01ecc69

Please sign in to comment.