-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFCMTokenSyncHandler.swift
More file actions
35 lines (31 loc) · 983 Bytes
/
FCMTokenSyncHandler.swift
File metadata and controls
35 lines (31 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// FCMTokenSyncHandler.swift
// DevLog
//
// Created by opfic on 3/19/26.
//
import Combine
import Foundation
final class FCMTokenSyncHandler {
private let userService: UserService
private let logger = Logger(category: "FCMTokenSyncHandler")
private var cancellables = Set<AnyCancellable>()
init(
userService: UserService,
notificationCenter: NotificationCenter = .default
) {
self.userService = userService
notificationCenter.publisher(for: .didRefreshFCMToken)
.compactMap { $0.userInfo?["fcmToken"] as? String }
.sink { [weak self] fcmToken in
Task {
do {
try await self?.userService.updateFCMToken(fcmToken)
} catch {
self?.logger.error("Failed to sync refreshed FCM token", error: error)
}
}
}
.store(in: &cancellables)
}
}