Skip to content

Commit abd6c00

Browse files
committed
refactor: Logger 추가 및 메서드 정리
1 parent a9fd340 commit abd6c00

1 file changed

Lines changed: 37 additions & 33 deletions

File tree

DevLog/App/Delegate/AppDelegate.swift

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,45 @@ private extension AppDelegate {
125125
}
126126
}
127127

128-
func startObservingBadgeCount() {
129-
cancellable = try? observeUnreadNotificationCount()
130-
.receive(on: DispatchQueue.main)
131-
.sink(
132-
receiveCompletion: { [weak self] completion in
133-
guard let self else { return }
134-
135-
if case .failure(let error) = completion {
136-
self.logger.error("Failed to observe unread notification count", error: error)
128+
func syncBadgeCount() {
129+
Task { @MainActor [weak self] in
130+
guard let self else { return }
131+
guard Auth.auth().currentUser != nil else {
132+
self.updateBadgeCount(0)
133+
return
134+
}
135+
136+
do {
137+
let unreadNotificationCount = try await self.fetchUnreadNotificationCount()
138+
self.updateBadgeCount(unreadNotificationCount)
139+
} catch {
140+
self.logger.error("Failed to fetch unread notification count", error: error)
141+
}
142+
}
143+
}
144+
145+
private func startObservingBadgeCount() {
146+
do {
147+
cancellable = try observeUnreadNotificationCount()
148+
.receive(on: DispatchQueue.main)
149+
.sink(
150+
receiveCompletion: { [weak self] completion in
151+
guard let self else { return }
152+
153+
if case .failure(let error) = completion {
154+
self.logger.error("Failed to observe unread notification count", error: error)
155+
}
156+
},
157+
receiveValue: { [weak self] count in
158+
self?.updateBadgeCount(count)
137159
}
138-
},
139-
receiveValue: { [weak self] count in
140-
self?.updateBadgeCount(count)
141-
}
142-
)
160+
)
161+
} catch {
162+
logger.error("Failed to start observing badge count", error: error)
163+
}
143164
}
144165

145-
func fetchUnreadNotificationCount() async throws -> Int {
166+
private func fetchUnreadNotificationCount() async throws -> Int {
146167
logger.info("Fetching unread notification count")
147168

148169
guard let uid = Auth.auth().currentUser?.uid else {
@@ -164,7 +185,7 @@ private extension AppDelegate {
164185
}
165186
}
166187

167-
func observeUnreadNotificationCount() throws -> AnyPublisher<Int, Error> {
188+
private func observeUnreadNotificationCount() throws -> AnyPublisher<Int, Error> {
168189
logger.info("Observing unread notification count")
169190

170191
guard let uid = Auth.auth().currentUser?.uid else {
@@ -194,23 +215,6 @@ private extension AppDelegate {
194215
.eraseToAnyPublisher()
195216
}
196217

197-
func syncBadgeCount() {
198-
Task { @MainActor [weak self] in
199-
guard let self else { return }
200-
guard Auth.auth().currentUser != nil else {
201-
self.updateBadgeCount(0)
202-
return
203-
}
204-
205-
do {
206-
let unreadNotificationCount = try await self.fetchUnreadNotificationCount()
207-
self.updateBadgeCount(unreadNotificationCount)
208-
} catch {
209-
self.logger.error("Failed to fetch unread notification count", error: error)
210-
}
211-
}
212-
}
213-
214218
@MainActor
215219
private func updateBadgeCount(_ count: Int) {
216220
UNUserNotificationCenter.current().setBadgeCount(count) { [weak self] error in

0 commit comments

Comments
 (0)