Skip to content

Commit

Permalink
[#63] RemoteConfigClient 구현
Browse files Browse the repository at this point in the history
- getMinimumVersion 내에 active 및 fetch 구현
  • Loading branch information
jayden000106 committed Feb 17, 2025
1 parent 3e0d5d1 commit efcbb71
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Soomsil-USaint/Application/AppReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct AppReducer {
}

enum Action {
case checkMinimumVersion
case checkMinimumVersionResponse(Result<String, Error>)
case initialize
case initResponse(Result<(StudentInfo, TotalReportCard), Error>)
case backgroundTask
Expand All @@ -31,12 +33,26 @@ struct AppReducer {
}

@Dependency(\.localNotificationClient) var localNotificationClient
@Dependency(\.remoteConfigClient) var remoteConfigClient
@Dependency(\.gradeClient) var gradeClient
@Dependency(\.studentClient) var studentClient

var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .checkMinimumVersion:
return .run { send in
await send(.checkMinimumVersionResponse(Result {
return try await remoteConfigClient.getMinimumVersion()
}))
}
case .checkMinimumVersionResponse(.success(let minimumVersion)):
debugPrint("MinimumVersion at AppReducer - \(minimumVersion)")
return .send(.initialize)
case .checkMinimumVersionResponse(.failure(let error)):
debugPrint("Error at AppReducer - \(error)")
// TODO: 에러 처리
return .none
case .initialize:
return .run { send in
await send(.initResponse(Result {
Expand Down
2 changes: 1 addition & 1 deletion Soomsil-USaint/Application/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct AppView: View {
case .initial:
SplashView()
.onAppear {
store.send(.initialize)
store.send(.checkMinimumVersion)
}
case .loggedOut:
if let store = store.scope(state: \.loggedOut, action: \.login) {
Expand Down
46 changes: 46 additions & 0 deletions Soomsil-USaint/Data/Client/Firebase/RemoteConfigClient.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// RemoteConfigClient.swift
// Soomsil-USaint
//
// Created by 정지혁 on 2/18/25.
//

import Foundation

import ComposableArchitecture
import FirebaseRemoteConfig

@DependencyClient
struct RemoteConfigClient {
private static let minimumVersionkey: String = "min_version_ios"

var getMinimumVersion: @Sendable () async throws -> String
}

extension DependencyValues {
var remoteConfigClient: RemoteConfigClient {
get { self[RemoteConfigClient.self] }
set { self[RemoteConfigClient.self] = newValue }
}
}

extension RemoteConfigClient: DependencyKey {
static let liveValue: RemoteConfigClient = Self(
getMinimumVersion: {
let remoteConfig = RemoteConfig.remoteConfig()
try await remoteConfig.fetchAndActivate()

let minimumVersion = remoteConfig[minimumVersionkey].stringValue
debugPrint(minimumVersion)
return minimumVersion
}
)

static let previewValue: RemoteConfigClient = Self(
getMinimumVersion: {
return "1.0.0"
}
)

static let testValue: RemoteConfigClient = previewValue
}

0 comments on commit efcbb71

Please sign in to comment.