77
88import Foundation
99import Combine
10+ import UserNotifications
1011
1112@Observable
1213final 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
109121private 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