2016-12-30 14 views
0

私は最初のViewController viewDidLoadでロードする次のコードを持っています。最初は正常に動作します。 10秒ごとに変更を探すべきではないでしょうか?Firebase RemoteConfigはフェッチを継続しますか?

Firebaseで設定値を更新して公開すると、アプリでこれが表示されません。私はデバッグモードで動作しているため、スロットリングは問題ではありません。

アプリを再起動すると、新しい値が表示されます。間隔が10秒に設定されているので、アプリの実行中に更新が表示されないはずです。

let rc = FIRRemoteConfig.remoteConfig() 

let interval: TimeInterval = 10 
    FIRRemoteConfig.remoteConfig().fetch(withExpirationDuration: interval) { 
     (status, error) in 

     guard error == nil else { 
      //handle error here 
      return 
     } 

     FIRRemoteConfig.remoteConfig().activateFetched() 
     let test = rc["key1"].stringValue //this runs only once 
    } 

これはなぜ更新されないのですか?

答えて

1

代わりにscheduledTimerを使用してください。

/// Fetches Remote Config data and sets a duration that specifies how long config data lasts. 
    /// Call activateFetched to make fetched data available to your app. 
    /// @param expirationDuration Duration that defines how long fetched config data is available, in 
    ///       seconds. When the config data expires, a new fetch is required. 
    /// @param completionHandler Fetch operation callback. 
    open func fetch(withExpirationDuration expirationDuration: TimeInterval, completionHandler: FirebaseRemoteConfig.FIRRemoteConfigFetchCompletion? = nil) 

fetch(withExpirationDuration: interval)は、タイムアウトを指定してデータをフェッチすることです。間隔です。

let interval: TimeInterval = 10 
Timer.scheduledTimer(timeInterval: interval, 
         target: self, 
         selector: #selector(updateConfig), 
         userInfo: nil, 
         repeats: true) 

func updateConfig() { 
    let rc = FIRRemoteConfig.remoteConfig() 

    FIRRemoteConfig.remoteConfig().fetch { (status, error) in 
     guard error == nil else { 
     //handle error here 
     return 
     } 

     FIRRemoteConfig.remoteConfig().activateFetched() 
     let test = rc["key1"].stringValue //this runs only once 
    } 
} 
+0

"expirationDuration。取得できるコンフィギュレーションデータの使用可能時間を秒単位で定義する期間"。 expirationDurationはフェッチされたデータをキャッシュする時間です。ネットワークタイムアウトではありません。 – user3296487

関連する問題