I'm setting up an AB test using Firebase Remote Config and I'm trying to get the app to print a value depending on which group it's in. But, the values aren't updating even though it says the values have been retrieved.
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
}
I have a RCValues file:
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 ?? ""
}
}
Then I use the pricing value when I want to check what group the user is in:
let group = RCValues.sharedInstance.string(forKey: .pricing)
print("your group is: \(group)")
But no matter what I do, I always end up getting "Control" printed, which is the default value I've set in the RCValues file for pricing. If I set it to something else in that file, it prints that.
What am I doing wrong?