Skip to content

Commit b0fea8a

Browse files
committed
fix: 로그아웃 시 앱 아이콘에 푸시알람 배지가 떠있는 이슈 해결
1 parent 7e472ed commit b0fea8a

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

DevLog/App/RootView.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ struct RootView: View {
2727
sessionUseCase: container.resolve(AuthSessionUseCase.self))
2828
)
2929
.onAppear {
30-
if viewModel.state.isFirstLaunch {
31-
viewModel.send(.setFirstLaunch(false))
32-
viewModel.send(.signOutAuto)
33-
}
30+
viewModel.send(.onAppear)
3431
}
3532
}
3633
} else {

DevLog/Presentation/ViewModel/RootViewModel.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import Foundation
99
import Combine
10+
import UserNotifications
1011

1112
@Observable
1213
final class RootViewModel: Store {
@@ -21,6 +22,7 @@ final class RootViewModel: Store {
2122
}
2223

2324
enum Action {
25+
case onAppear
2426
case setAlert(Bool)
2527
case networkStatusChanged(Bool)
2628
case setFirstLaunch(Bool)
@@ -30,6 +32,7 @@ final class RootViewModel: Store {
3032
}
3133

3234
enum SideEffect {
35+
case clearApplicationBadgeCount
3336
case signOut
3437
}
3538

@@ -70,6 +73,13 @@ final class RootViewModel: Store {
7073
var effects: [SideEffect] = []
7174

7275
switch action {
76+
case .onAppear:
77+
effects = [.clearApplicationBadgeCount]
78+
if state.isFirstLaunch {
79+
state.isFirstLaunch = false
80+
updateFirstLaunchUseCase.execute(false)
81+
effects.append(.signOut)
82+
}
7383
case .setAlert(let isPresented):
7484
setAlert(&state, isPresented: isPresented)
7585
case .networkStatusChanged(let isConnected):
@@ -95,6 +105,8 @@ final class RootViewModel: Store {
95105

96106
func run(_ effect: SideEffect) {
97107
switch effect {
108+
case .clearApplicationBadgeCount:
109+
clearApplicationBadgeCount()
98110
case .signOut:
99111
Task {
100112
try? await signOutUseCase.execute()
@@ -107,6 +119,10 @@ final class RootViewModel: Store {
107119

108120
// MARK: - Helper Methods
109121
private extension RootViewModel {
122+
func clearApplicationBadgeCount() {
123+
UNUserNotificationCenter.current().setBadgeCount(0) { _ in }
124+
}
125+
110126
func setAlert(
111127
_ state: inout State,
112128
isPresented: Bool

0 commit comments

Comments
 (0)