0

我需要使用之前选择的一组用户来测试我的应用的某些功能。基于用户属性的Firebase观众

我创造了一个观众,其中user_id exactly matches 123456123456是我自己的ID。

在远程配置中,我创建了一个与上面的受众群体中的用户匹配的条件。

然后,我在远程配置中创建了一个名为feature_available的参数,对于该条件,我设置了返回值true。默认值是false

在我的应用我建立了火力地堡:

FIRApp.configure() 

    let remoteConfig = FIRRemoteConfig.remoteConfig() 
    if let remoteConfigSettings = FIRRemoteConfigSettings(developerModeEnabled: false) { 
     remoteConfig.configSettings = remoteConfigSettings 
    } 
    remoteConfig.setDefaultsFromPlistFileName("FirebaseRemoteConfigDefaults") 

,并设置用户ID:

FIRAnalytics.setUserID("123456") 

然后我从火力地堡获取:

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,我无法设法让它返回与我创建的受众群相匹配的正确值。 我也试过设置一个用户属性而不是使用setUserID()并得到了相同的结果。 有什么建议吗?

回答

0

我发了电子邮件给火力地堡队请求支援,他们告诉我,这个问题是用斯威夫特在Xcode 8(1.0和1.1)的错误。 更新至今天发布的最新版本8.2,修复了此问题。

0

我以前遇到过类似的问题,有时可能需要一段时间才能完成抓取。检查功能是否可用需要在配置成功修复时完成。像这样的东西希望能对你的作品还有:

var featureIsAvailable : Bool? 

override func viewDidLoad() { 
    super.viewDidLoad() 

    configureRemoteConfig() 
    fetchConfig()  
} 

func configureRemoteConfig() { 
    remoteConfig = FIRRemoteConfig.remoteConfig() 
    // Create Remote Config Setting to enable developer mode. 
    // Fetching configs from the server is normally limited to 5 requests per hour. 
    // Enabling developer mode allows many more requests to be made per hour, so developers 
    // can test different config values during development. 
    let remoteConfigSettings = FIRRemoteConfigSettings(developerModeEnabled: true) 
    remoteConfig.configSettings = remoteConfigSettings! 
    remoteConfig.setDefaultsFromPlistFileName("RemoteConfigDefaults") 
} 

func fetchConfig() { 
    var expirationDuration: Double = 3600 
    // If in developer mode cacheExpiration is set to 0 so each fetch will retrieve values from 
    // the server. 
    if (self.remoteConfig.configSettings.isDeveloperModeEnabled) { 
     expirationDuration = 0 
    } 

    // cacheExpirationSeconds is set to cacheExpiration here, indicating that any previously 
    // fetched and cached config would be considered expired because it would have been fetched 
    // more than cacheExpiration seconds ago. Thus the next fetch would go to the server unless 
    // throttling is in progress. The default expiration duration is 43200 (12 hours). 
    remoteConfig.fetch(withExpirationDuration: expirationDuration) { (status, error) in 
     if (status == .success) { 
      print("Config fetched!") 
      self.remoteConfig.activateFetched() 

      let featureIsAvailable = self.remoteConfig["feature_available"] 

      if (featureIsAvailable.source != .static) { 
       self.featureIsAvailable = featureIsAvailable.boolValue 
       print("should the feature be available?", featureIsAvailable!) 
      } 
     } else { 
      print("Config not fetched") 
      print("Error \(error)") 
     } 
     self.checkIfFeatureIsAvailable() 
    } 
} 

func checkIfFeatureIsAvailable() { 
    if featureIsAvailable == false { 
     // Don't show new feature 
    } else { 
     // Show new feature 
    } 
} 
+0

谢谢Jordi,但这基本上是我在做什么。 当我的抓取成功时,应该被接收为'true'的值全部为'false'。 TBH,我不相信这是我的代码的东西,但与Firebase的东西,为观众返回错误的价值。 – Tchelow

+0

@Tchelow我一定是错误地读了他们的问题,我的坏! –