ios - 需要将 firebase 远程配置中的值更新到我的 plist

标签 ios swift xcode firebase

在我的 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。这样我就可以在我的应用程序中使用这些值。

现在,当我在 func fetchConfig() { 中打印 print(DataVal) 时,值没有出现。

最佳答案

你走在正确的道路上。 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

关于ios - 需要将 firebase 远程配置中的值更新到我的 plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55057554/

相关文章:

ios - 带有水平动画的Viewcontroller背景图片

objective-c - #pragma 标记的意义​​是什么?为什么我们需要#pragma 标记?

ios - 在 Xcode 和 IOS 项目中,我不能使用常量。得到链接器构建错误

iphone - 尝试使用 MPMoviePlayer 时出现链接器错误

ios - 上传的视频没有显示在 vine 应用程序上

ios - UITableViewCell 内容在单独重新加载单元格时闪烁

ios - 如果json数据为零,如何在tableview中隐藏单元格

swift - 背景颜色清晰的 UIToolbar 在 iOS 10 中变为白色

ios - 如何从滤镜中获取原始图像

ios - 表格数据 iOS