Skip to content

Commit

Permalink
chore: fix double notification routing and segment callback (#473)
Browse files Browse the repository at this point in the history
* chore: fix double notification routing and segment callback

* refactor: address review feedback

* refactor: address review feedback
  • Loading branch information
saeedbashir authored Jul 8, 2024
1 parent ea6e24e commit 9901340
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import Swinject

class BrazeListener: PushNotificationsListener {

Expand All @@ -24,6 +25,11 @@ class BrazeListener: PushNotificationsListener {
func didReceiveRemoteNotification(userInfo: [AnyHashable: Any]) {
guard let dictionary = userInfo as? [String: AnyHashable],
shouldListenNotification(userinfo: userInfo) else { return }

if let segmentService = Container.shared.resolve(SegmentAnalyticsService.self) {
segmentService.analytics?.receivedRemoteNotification(userInfo: userInfo)
}

let link = PushLink(dictionary: dictionary)
deepLinkManager.processLinkFromNotification(link)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import SegmentBrazeUI
import Swinject

class BrazeProvider: PushNotificationsProvider {

func didRegisterWithDeviceToken(deviceToken: Data) {
guard let segmentService = Container.shared.resolve(SegmentAnalyticsService.self) else { return }
segmentService.analytics?.add(
plugin: BrazeDestination(
additionalConfiguration: { configuration in
configuration.logger.level = .debug
configuration.logger.level = .info
}, additionalSetup: { braze in
braze.notifications.register(deviceToken: deviceToken)
}
)
)

segmentService.analytics?.registeredForRemoteNotifications(deviceToken: deviceToken)
}

func didFailToRegisterForRemoteNotificationsWithError(error: Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class PushNotificationsManager: NSObject {
private let deepLinkManager: DeepLinkManager
private let storage: CoreStorage
private let api: API

private var providers: [PushNotificationsProvider] = []
private var listeners: [PushNotificationsListener] = []

Expand All @@ -37,10 +38,16 @@ class PushNotificationsManager: NSObject {
}

// Init manager
public init(deepLinkManager: DeepLinkManager, storage: CoreStorage, api: API, config: ConfigProtocol) {
public init(
deepLinkManager: DeepLinkManager,
storage: CoreStorage,
api: API,
config: ConfigProtocol
) {
self.deepLinkManager = deepLinkManager
self.storage = storage
self.api = api

super.init()
providers = providersFor(config: config)
listeners = listenersFor(config: config)
Expand Down Expand Up @@ -129,6 +136,7 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
) async -> UNNotificationPresentationOptions {
if UIApplication.shared.applicationState == .active {
didReceiveRemoteNotification(userInfo: notification.request.content.userInfo)
return []
}

return [[.list, .banner, .sound]]
Expand Down

0 comments on commit 9901340

Please sign in to comment.