Firebase远程配置不更新值?

时间:2019-06-08 12:13:24

标签: swift firebase firebase-remote-config

我正在使用Firebase Remote Config设置AB测试,并且试图使应用程序根据其所在的组来打印值。但是,即使该值表明具有已被检索。

AppDelegate

var window: UIWindow?
var remoteConfig:RCValues!

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

    FirebaseApp.configure()
    self.remoteConfig = RCValues.sharedInstance

    return true
}

我有一个RCValues文件:

enum ValueKey: String {
    case pricing
}

class RCValues {

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

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

    func loadDefaultValues() {
        let appDefaults: [String: Any?] = [
            ValueKey.pricing.rawValue: "Control"
        ]
        RemoteConfig.remoteConfig().setDefaults(appDefaults as? [String: NSObject])
    }

    func fetchCloudValues() {
        let fetchDuration: TimeInterval = 0
        activateDebugMode()
        RemoteConfig.remoteConfig().fetch(withExpirationDuration: fetchDuration) {
            [weak self] (status, error) in

            if let error = error {
                print ("Uh-oh. Got an error fetching remote values \(error)")
                return
            }

            RemoteConfig.remoteConfig().activateFetched()
            print ("Retrieved values from the cloud!")
            self?.fetchComplete = true
            self?.loadingDoneCallback?()
        }
    }

    func activateDebugMode() {
        let debugSettings = RemoteConfigSettings(developerModeEnabled: true)
        RemoteConfig.remoteConfig().configSettings = debugSettings
    }

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

}

然后,当我要检查用户所在的组时,我使用pricing值:

let group = RCValues.sharedInstance.string(forKey: .pricing)
print("your group is: \(group)")

但是无论做什么,我总是最终打印出“控件”,这是我在RCValues文件中为pricing设置的默认值。如果我将其设置为该文件中的其他内容,它将打印出来。

我在做什么错?

1 个答案:

答案 0 :(得分:0)

从firebase获得价值之后,您什么也不做。提取完成后添加功能并打印新值。我认为您在获得新的价值后没有做任何事情。