firebase-kotlin-sdk icon indicating copy to clipboard operation
firebase-kotlin-sdk copied to clipboard

Does not receive data from RemoteConfig

Open Reksagon opened this issue 2 years ago • 1 comments
trafficstars

class FirebaseClient {

    private val remoteConfig: FirebaseRemoteConfig = Firebase.remoteConfig

    enum class ConfigValues(val value: String)
    {
        API_KEY("api_key"),
        PREFIX("prefix"),
        SECRET("secret"),
        SERVER("server")
    }

    fun getString(configValue: ConfigValues): String {
            return remoteConfig.getValue(configValue.value).asString().base64Decoded
    }
}

image

does not receive data from the config, everything is ok in the native code, can something be done? somehow initialize or how? it is not clear, because there is no documentation

Reksagon avatar Jul 04 '23 14:07 Reksagon

Have you called fetchAndActivate()? If not, create this in the shared module (it could be done better, maybe without using GlobalScope)

// FirebaseUtils.kt

fun initFirebaseRemoteConfig() {
    GlobalScope.launch {
        Firebase.remoteConfig.settings {
            minimumFetchIntervalInSeconds = 0
        }
        Firebase.remoteConfig.fetchAndActivate()
    }
}

Then for the Android module

Add this to the manifest

 <application
        android:name=".MainApplication"
...

This in the Application file


// MainApplication.kt

class MainApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        // ..
        Firebase.initialize(this)
        initFirebaseRemoteConfig()
        // ...
    }
}

And this in the iOS module


// iOSApp.swift

import SwiftUI
import FirebaseCore
import shared

@main
struct iOSApp: App {

    @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate

    init() {
        // ...
        FirebaseApp.configure()
        FirebaseUtilsKt.initFirebaseRemoteConfig()
        // ...
    }
 
    // ...

}

dogeweb avatar Sep 06 '23 18:09 dogeweb

Closing as solution provided

nbransby avatar Apr 10 '24 05:04 nbransby