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