2016-12-30 76 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