我正在使用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
设置的默认值。如果我将其设置为该文件中的其他内容,它将打印出来。
我在做什么错?
答案 0 :(得分:0)
从firebase获得价值之后,您什么也不做。提取完成后添加功能并打印新值。我认为您在获得新的价值后没有做任何事情。