我需要使用之前选择的一组用户来测试我的应用程序的某些功能 .
我创建了一个 Spectator user_id exactly matches 123456
. 123456
是我自己的身份证 .
在远程配置中,我创建了一个与上述受众中的用户匹配的条件 .
然后我在Remote Config中创建了一个名为 feature_available
的参数,对于这个条件,我设置了一个返回值 true
. 默认值为 false
.
在我的应用中,我设置了Firebase:
FIRApp.configure()
let remoteConfig = FIRRemoteConfig.remoteConfig()
if let remoteConfigSettings = FIRRemoteConfigSettings(developerModeEnabled: false) {
remoteConfig.configSettings = remoteConfigSettings
}
remoteConfig.setDefaultsFromPlistFileName("FirebaseRemoteConfigDefaults")
并设置用户ID:
FIRAnalytics.setUserID("123456")
然后我从Firebase获取:
var expirationDuration: Double
// If in developer mode cacheExpiration is set to 0 so each fetch will retrieve values from the server.
expirationDuration = remoteConfig.configSettings.isDeveloperModeEnabled ? 0 : 3600
remoteConfig.fetch(withExpirationDuration: TimeInterval(expirationDuration)) { (status, error) -> Void in
if status == .success {
remoteConfig.activateFetched()
} else {
assertionFailure("Firebase config not fetched. Error \(error!.localizedDescription)")
}
}
我做的最后一件事是从Firebase获取值并检查我是否启用了该功能:
let featureIsAvailable = remoteConfig["feature_available"].boolValue
if featureIsAvailable { ... }
问题是,每次从Firebase返回的值都是 false
,我无法让它返回与我创建的Audience匹配的正确值 . 我也尝试设置用户属性而不是使用 setUserID()
并且具有相同的结果 . 有什么建议?
2 回答
我之前遇到过类似的问题,有时可能需要一段时间才能完成获取 . 成功修复配置后,需要检查功能是否可用 . 这样的东西也有希望对你有用:
我向Firebase团队发送了一封电子邮件,请求支持,他们告诉我这个问题是使用Swift的Xcode 8(.0和.1)中的一个错误 . 更新到今天发布的最新版本,8.2,修复了该问题 .