【问题标题】:Why Firebase Remote Config doesn't update values?为什么 Firebase 远程配置不更新值?
【发布时间】:2019-06-14 21:43:50
【问题描述】:

我正在使用 Firebase 远程配置,我在更新值时遇到了一些麻烦。 仅当我关闭并重新启动应用程序时,我的值才会更新。

但如果我的应用进入前台,则永远不会。

开发者被激活,没有缓存延迟。

类 AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        let _ = RCFirebaseValues.sharedInstance
    }
}

我的 Firebase 远程配置类:

enum ValueKey: String {
    case force_update
}

class RCFirebaseValues {

    static let sharedInstance = RCFirebaseValues()
    var loadingDoneCallback: (() -> ())?
    var fetchComplete: Bool = false

    private init() {    
        loadDefaultValues()
        fetchCloudValues()
    }

    func loadDefaultValues() {
       RemoteConfig.remoteConfig().setDefaults(fromPlist: "RemoteConfigDefaults")
    }

    func fetchCloudValues() {

        #if DEBUG
        let expirationDuration: TimeInterval = 0
        RemoteConfig.remoteConfig().configSettings = RemoteConfigSettings(developerModeEnabled: true)
        #else
        let expirationDuration: TimeInterval = 3600
        #endif

        RemoteConfig.remoteConfig().fetch(withExpirationDuration: expirationDuration) {
            [weak self] (status, error) in

            guard error == nil else {
                DLog(message:"Uh-oh. Got an error fetching remote values \(String(describing: error))")
                return
            }

            RemoteConfig.remoteConfig().activateFetched()

            self?.fetchComplete = true
            self?.loadingDoneCallback?()
        }
    }


    func bool(forKey key: ValueKey) -> Bool {
        return RemoteConfig.remoteConfig()[key.rawValue].boolValue
    }

    func string(forKey key: ValueKey) -> String {
        return RemoteConfig.remoteConfig()[key.rawValue].stringValue ?? ""
    }

    func double(forKey key: ValueKey) -> Double {
        if let numberValue = RemoteConfig.remoteConfig()[key.rawValue].numberValue {
            return numberValue.doubleValue
        } else {
            return 0.0
        }
    }
}

怎么了?

在 Mosbah 回复后编辑:

class AppDelegate: UIResponder, UIApplicationDelegate {

     var remoteConfig:RCFirebaseValues!

     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
         FirebaseApp.configure()
         self. remoteConfig = RCFirebaseValues.sharedInstance
      }

}

【问题讨论】:

    标签: ios swift firebase firebase-remote-config


    【解决方案1】:

    您的RCFirebaseValues 范围是错误的,一旦您离开application: didFinishLaunchingWithOptions:,它将为零,因此您应该保持对您的对象的强引用(在 AppDelegate 上创建一个 var)。

    【讨论】:

    • 这个:self.firebaseRC = RCFirebaseValues.sharedInstance?我试过了,但结果相同,值没有更新:(
    • 是的,当然,我添加了对应用委托的 var 引用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    相关资源
    最近更新 更多