4

So I've set up an A/B Test Experiment a couple times now, and regardless of whether it's in the "draft" phase (where I target my test devices using InstanceID.instanceID().token()) or in a fully started and running experiment (where I set for 100% of users matching my app bundle ID), I'm not seeing the parameter in my test variant arriving in Remote Config when I do:

func loadRemoteConfig()
{
    let remoteConfig = RemoteConfig.remoteConfig()
    let remoteConfigSettings = RemoteConfigSettings(developerModeEnabled: true)
    remoteConfig.configSettings = remoteConfigSettings!

    remoteConfig.setDefaults(fromPlist: "RemoteConfigDefaults")

    remoteConfig.fetch(withExpirationDuration: TimeInterval(1)) { (status, error) in

        if let actualError = error
        {
            DDLogError("error from loadRemoteConfig is \(actualError.localizedDescription)")
        } else {
            switch(status)
            {
            case RemoteConfigFetchStatus.noFetchYet, RemoteConfigFetchStatus.failure, RemoteConfigFetchStatus.throttled :
                DDLogDebug("loadRemoteConfig got a \(status) status")
            case RemoteConfigFetchStatus.success :
                break
            }

            remoteConfig.activateFetched()

            // my A/B test parameter doesn't arrive in this array, ever.
            let arrayOfKeys = remoteConfig.allKeys(from: RemoteConfigSource.remote, namespace: NamespaceGoogleMobilePlatform)
            print("array of keys is \(arrayOfKeys.count) & \(arrayOfKeys)")

            // do some stuff here, depending on what Firebase tells us to do...
        }
    }

    self.remoteConfig = remoteConfig
}

This code lives in the initial view controller and not the app delegate.

Here's what my Firebase A/B page looks like, where I simply want to show a tooltip for a demo:

Firebase Experiment Page

How can I get that A/B test & experiment parameter to appear with a RemoteConfig fetch?

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215

1 Answers1

2

Okay! This is one of those problems where I solved it myself.

The key to what was happening was in this sentence of my question:

This code lives in the initial view controller and not the app delegate.

What was happening is that applicationDidFinishLaunching: wasn't necessarily finished (or, more specifically, the result or completion block of remoteConfig.fetch hadn't fired before the end of applicationDidFinishLaunching).

So I was checking the remote config values in the initial view controller's viewDidLoad function before remoteConfig had retrieved an update from Firebase.

Sending a notification to newly registered observers from the result of remoteConfig.fetch allowed me to get my A/B test parameter to appear.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215