From 013cf81a17ef7941ba7f9cb6b71b7137c2b2925d Mon Sep 17 00:00:00 2001 From: ryoya ito Date: Wed, 13 Sep 2023 01:22:03 +0900 Subject: [PATCH] enable realtime updates for remote config on iOS --- .../Sources/RemoteConfig/RemoteConfig.swift | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app-ios/Modules/Sources/RemoteConfig/RemoteConfig.swift b/app-ios/Modules/Sources/RemoteConfig/RemoteConfig.swift index 37a05ae2d..c5068fa7d 100644 --- a/app-ios/Modules/Sources/RemoteConfig/RemoteConfig.swift +++ b/app-ios/Modules/Sources/RemoteConfig/RemoteConfig.swift @@ -2,13 +2,27 @@ import FirebaseRemoteConfig import shared public class RemoteConfigApiImpl: RemoteConfigApi { - public init() {} + private let remoteConfig = RemoteConfig.remoteConfig() + + public init() { + remoteConfig.addOnConfigUpdateListener { [weak remoteConfig] configUpdate, error in + guard let configUpdate, error == nil else { + print("Error listening for config updates: \(error)") + return + } + + print("Updated keys: \(configUpdate.updatedKeys)") + + remoteConfig?.activate() + } + } + public func getBoolean(key: String) async throws -> KotlinBoolean { .init( - bool: RemoteConfig.remoteConfig().configValue(forKey: key).boolValue + bool: remoteConfig.configValue(forKey: key).boolValue ) } public func getString(key: String) async throws -> String { - return RemoteConfig.remoteConfig().configValue(forKey: key).stringValue ?? "" + return remoteConfig.configValue(forKey: key).stringValue ?? "" } }