需要将firebase远程配置中的值更新为我的plist

问题描述 投票:0回答:1

在我的firebase远程配置中,我有一个名为的参数:

"uniquId" = {[1,2,3,4,5,6,7,8,9,10,11,12,14,14]}

我创造了一个plist:FireStoreRemoteConfig

现在我需要从firebase远程配置中获取值,并且需要将值存储在plist中,我需要在我的应用程序中使用该数组值。

在我的appdelegate

import FirebaseRemoteConfig
 func applicationDidBecomeActive(_ application: UIApplication) {
setUpAppRemoteConfig()
}
func setUpAppRemoteConfig()
    {
        remoteConfig = RemoteConfig.remoteConfig()
        let remoteConfigSettings = RemoteConfigSettings(developerModeEnabled: true)
        remoteConfig.configSettings = remoteConfigSettings
        remoteConfig.setDefaults(fromPlist: "FireStoreRemoteConfig")
        fetchConfig()
    }
 func fetchConfig() {
        print("fetched from firestore")
        let DataVal = remoteConfig[sampleURLConfigKey].stringValue
        print(DataVal)

    }

在我的plist文件中,我创建了一个参数名为uniquId且数值为空的数组。

现在,每次我启动我的应用程序。我需要从firestore获取值并更新到我的plist。这样我就可以在我的应用程序中使用这些值。

现在,当我在print(DataVal)打印func fetchConfig() {时,价值不会到来。

ios swift xcode firebase
1个回答
0
投票

你走在正确的轨道上。 fetchConfig()中只缺少小代码。您尚未从远程配置中获取值或数据。

您更新的代码应如下所示:

func fetchConfig() {

        // You can give your required duration
        var expirationDuration = 3600
        if remoteConfig.configSettings.isDeveloperModeEnabled {
            expirationDuration = 0
        }

        remoteConfig.fetch(withExpirationDuration: TimeInterval(expirationDuration)) { (status, error) -> Void in
            if status == .success {
                print("Config fetched!")
                self.remoteConfig.activateFetched()
            } else {
                print("Config not fetched")
                print("Error \(error!.localizedDescription)")
            }
            let DataVal = self.remoteConfig[self.sampleURLConfigKey].stringValue
            // You can print and check your  DataVal.



        }

检查一下:Firebase Remote Config iOS

© www.soinside.com 2019 - 2024. All rights reserved.