GitLiveApp / firebase-kotlin-sdk

A Kotlin-first SDK for Firebase
https://gitliveapp.github.io/firebase-kotlin-sdk/
Apache License 2.0
1.17k stars 155 forks source link

Does not receive data from RemoteConfig #396

Closed Reksagon closed 7 months ago

Reksagon commented 1 year ago
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

dogeweb commented 1 year ago

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()
        // ...
    }

    // ...

}
nbransby commented 7 months ago

Closing as solution provided