2016-11-24 99 views
1

我正在使用Firebase的RemoteConfig框架。 從Firebase服務器提取數據可以正常工作(已在生產環境中工作),但設置默認值似乎不起作用。我試圖堅持文檔,但也許我做錯了什麼。Firebase無法設置RemoteConfig的默認設置

爲了驗證這一點,我做了以下內容:

[self.remoteConfig setDefaults:@{@"key1": @"value1"}]; 

然後,在Firebase Console我設置參數key1有發送零數據到客戶端的默認No Value。我沒有定義任何其他條件,所以這是將被髮送的唯一值。根據documentation,在這種情況下,RemoteConfig對象應該選擇默認值。

取代碼:

[self.remoteConfig fetchWithExpirationDuration:self.configurationExpirationDuration 
          completionHandler:^(FIRRemoteConfigFetchStatus status, 
               NSError * _Nullable error) { 
    if (status == FIRRemoteConfigFetchStatusSuccess) { 
    [self.remoteConfig activateFetched]; 

    FIRRemoteConfigValue *remoteValue1 = [self.remoteConfig configValueForKey:@"key1"]; 
    NSString *value1 = remoteValue1.stringValue; 

    // Logic comes here 

    } else { 
    LogError(@"Error fetching remote configuration from Firebase: %@", error); 
} 

remoteValue1nil

value1nil

remoteValue1.dataValue_NSZeroData

而且,當我嘗試使用

[self.remoteConfig defaultValueForKey:@"key1" namespace:nil] 

我得到一個nil值(假設發送nil到作爲namespace參數會給我默認命名空間的默認值)。

我在這裏做錯了什麼?

回答

1

configValueForKey:方法首先檢查從Firebase服務器獲取的結果,如果結果存在,則返回遠程結果而不是默認結果。

所以key1值應該是你在控制檯中設置的值,它是零(無值)。

當您調用defaultVaueForKey:namespace時:應始終使用默認名稱空間FIRNamespaceGoogleMobilePlatform。使用nil不會返回任何有效的配置結果。

+0

謝謝,我不知何故錯過了頭文件中的FIRNamespaceGoogleMobilePlatform常量。 –