远程配置A / B测试不会在测试设备上触发(或100%匹配)

时间:2018-03-01 22:53:36

标签: ios firebase ab-testing firebase-remote-config

所以我现在已经设置了几次A / B测试实验,无论它是处于“草稿”阶段(我使用InstanceID.instanceID().token()定位我的测试设备)还是完全启动和运行实验(我为100%匹配我的应用程序包ID的用户设置),当我这样做时,我没有看到我的测试变体中的参数到达Remote Config:

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
}

此代码位于初始视图控制器中,而不是应用程序委托。

以下是我的Firebase A / B页面的样子,我只想在其中显示演示的工具提示:

Firebase Experiment Page

如何进行A / B测试&使用RemoteConfig fetch显示实验参数?

1 个答案:

答案 0 :(得分:1)

好!这是我自己解决的问题之一。

发生的事情的关键在于我的问题的这句话:

  

此代码位于 初始视图控制器 ,而不是应用代理。

发生的事情是applicationDidFinishLaunching:未必完成(或者更具体地说,remoteConfig.fetch的结果或完成块在applicationDidFinishLaunching结束之前未被触发)。

所以我在remoteConfig从Firebase检索到更新之前检查了初始视图控制器的viewDidLoad函数中的远程配置值。

remoteConfig.fetch的结果向新注册的观察者发送通知,让我可以看到我的A / B测试参数。