Skip to content

Commit ebda5bb

Browse files
committed
Feat: 강제 업데이트 로직 구현
1 parent 223493b commit ebda5bb

3 files changed

Lines changed: 71 additions & 3 deletions

File tree

Projects/Presentation/Sources/Common/PresentationDependencyAssembler.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ public struct PresentationDependencyAssembler: DependencyAssemblerProtocol {
2828
guard let emotionUseCase = container.resolve(type: EmotionUseCaseProtocol.self)
2929
else { fatalError("emotionUseCase 의존성이 등록되지 않았습니다.") }
3030

31+
guard let appConfigRepository = container.resolve(type: AppConfigRepositoryProtocol.self)
32+
else { fatalError("appConfigRepository 의존성이 등록되지 않았습니다.") }
33+
34+
3135
return HomeViewModel(
3236
routineUseCase: routineUseCase,
3337
userDataUseCase: userDataUseCase,
34-
emotionUseCase: emotionUseCase)
38+
emotionUseCase: emotionUseCase,
39+
appConfigRepository: appConfigRepository)
3540
}
3641

3742
DIContainer.shared.register(type: LoginViewModel.self) { container in

Projects/Presentation/Sources/Home/View/HomeViewController.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ final class HomeViewController: BaseViewController<HomeViewModel> {
103103
super.viewDidLoad()
104104
showIndicatorView()
105105
viewModel.action(input: .loadNickname)
106+
viewModel.action(input: .fetchVersion)
106107
}
107108

108109
override func viewWillAppear(_ animated: Bool) {
@@ -461,6 +462,35 @@ final class HomeViewController: BaseViewController<HomeViewModel> {
461462
self?.weekView.updateAllCompletedState(allCompletedDates: allCompletedDates)
462463
}
463464
.store(in: &cancellables)
465+
466+
viewModel.output.updateVersionPublisher
467+
.receive(on: DispatchQueue.main)
468+
.sink { [weak self] updateURL in
469+
guard let updateURL else { return }
470+
471+
let alert = UIAlertController(
472+
title: "업데이트가 필요합니다",
473+
message: "원활한 이용을 위해, 빛나길을 업데이트 해주세요!",
474+
preferredStyle: .alert
475+
)
476+
477+
let cancel = UIAlertAction(
478+
title: "취소",
479+
style: .default,
480+
handler: { _ in exit(0) })
481+
let update = UIAlertAction(
482+
title: "업데이트",
483+
style: .default,
484+
handler: { _ in
485+
UIApplication.shared.open(updateURL, options: [:], completionHandler: { _ in exit(0) })
486+
})
487+
488+
alert.addAction(cancel)
489+
alert.addAction(update)
490+
alert.preferredAction = update
491+
self?.present(alert, animated: true)
492+
}
493+
.store(in: &cancellables)
464494
}
465495

466496
// 해당 날짜의 Routine View를 설정합니다. (없다면 EmptyView)

Projects/Presentation/Sources/Home/ViewModel/HomeViewModel.swift

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ final class HomeViewModel: ViewModel {
2020
case fetchDailyRoutine
2121
case refreshDailyRoutine
2222
case updateRoutineCompletion(updatedRoutine: Routine)
23+
case fetchVersion
2324
}
2425

2526
struct Output {
@@ -31,6 +32,7 @@ final class HomeViewModel: ViewModel {
3132
let routinesPublisher: AnyPublisher<[Routine], Never>
3233
let updateRoutineCompletionResultPublisher: AnyPublisher<Bool, Never>
3334
let allCompletedRoutineDatePublisher: AnyPublisher<[Date], Never>
35+
let updateVersionPublisher: AnyPublisher<URL?, Never>
3436
}
3537

3638
private(set) var output: Output
@@ -45,6 +47,7 @@ final class HomeViewModel: ViewModel {
4547
private let selectedRoutineSubject = CurrentValueSubject<Routine?, Never>(nil)
4648
private let updateRoutineCompletionResultSubject = PassthroughSubject<Bool, Never>()
4749
private let allCompletedRoutineDateSubject = CurrentValueSubject<[Date], Never>([])
50+
private let updateVersionSubject = PassthroughSubject<URL?, Never>()
4851

4952
private let calendar = Calendar.current
5053
private let today = Date()
@@ -54,14 +57,18 @@ final class HomeViewModel: ViewModel {
5457
private let routineUseCase: RoutineUseCaseProtocol
5558
private let userDataUseCase: UserDataUseCaseProtocol
5659
private let emotionUseCase: EmotionUseCaseProtocol
60+
private let appConfigRepository: AppConfigRepositoryProtocol
61+
5762
init(
5863
routineUseCase: RoutineUseCaseProtocol,
5964
userDataUseCase: UserDataUseCaseProtocol,
60-
emotionUseCase: EmotionUseCaseProtocol
65+
emotionUseCase: EmotionUseCaseProtocol,
66+
appConfigRepository: AppConfigRepositoryProtocol
6167
) {
6268
self.routineUseCase = routineUseCase
6369
self.userDataUseCase = userDataUseCase
6470
self.emotionUseCase = emotionUseCase
71+
self.appConfigRepository = appConfigRepository
6572
self.output = Output(
6673
nicknamePublisher: nicknameSubject.eraseToAnyPublisher(),
6774
emotionPublisher: emotionSubject.eraseToAnyPublisher(),
@@ -70,7 +77,8 @@ final class HomeViewModel: ViewModel {
7077
fetchRoutineResultPublisher: fetchRoutineResultSubject.eraseToAnyPublisher(),
7178
routinesPublisher: routinesSubject.eraseToAnyPublisher(),
7279
updateRoutineCompletionResultPublisher: updateRoutineCompletionResultSubject.eraseToAnyPublisher(),
73-
allCompletedRoutineDatePublisher: allCompletedRoutineDateSubject.eraseToAnyPublisher())
80+
allCompletedRoutineDatePublisher: allCompletedRoutineDateSubject.eraseToAnyPublisher(),
81+
updateVersionPublisher: updateVersionSubject.eraseToAnyPublisher())
7482
}
7583

7684
func action(input: Input) {
@@ -102,6 +110,9 @@ final class HomeViewModel: ViewModel {
102110

103111
case .refreshDailyRoutine:
104112
refreshSelectedDateRoutines()
113+
114+
case .fetchVersion:
115+
checkVersion()
105116
}
106117
}
107118

@@ -262,4 +273,26 @@ final class HomeViewModel: ViewModel {
262273
}
263274
}
264275
}
276+
277+
private func checkVersion() {
278+
let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
279+
let major = currentVersion?.split(separator: ".").first
280+
281+
Task {
282+
do {
283+
let appStoreAppVersion = try await appConfigRepository.fetchAppVersion()
284+
let appStoreMajor = appStoreAppVersion?.split(separator: ".").first
285+
286+
if major != appStoreMajor {
287+
let url = URL(string: "itms-apps://itunes.apple.com/app/id6749437799")
288+
updateVersionSubject.send(url)
289+
} else {
290+
updateVersionSubject.send(nil)
291+
}
292+
293+
} catch {
294+
295+
}
296+
}
297+
}
265298
}

0 commit comments

Comments
 (0)