Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add timeout on Firebase RemoteConfig fetch request?

I am using Firebase Remote Config feature in my app. I need to add a network timeout on the fetch request.

#if DEBUG
let expirationDuration: TimeInterval = 0
RemoteConfig.remoteConfig().configSettings = RemoteConfigSettings(developerModeEnabled: true)
#else
let expirationDuration: TimeInterval = 3600
#endif

RemoteConfig.remoteConfig().fetch(withExpirationDuration: expirationDuration) {
    [weak self] (status, error) in

    guard error == nil else {
        print ("Uh-oh. Got an error fetching remote values \(String(describing: error))")
            return
        }

    RemoteConfig.remoteConfig().activateFetched()

    self?.fetchComplete = true
    self?.loadingDoneCallback?()
}

How can I do?

like image 286
cmii Avatar asked Jun 07 '18 15:06

cmii


2 Answers

You can have a workaround for that by using a timer:

  remoteConfigTimer = Timer.scheduledTimer(withTimeInterval: 10,
                                                 repeats: false) {
                                                    timer in
                                                    self.remoteConfigTimerExpired = true
                                                    self.loadingDoneCallback()
  }

Here you define your timeout as the timeInterval of your Timer, and once this timer is reached you just execute the same method you would execute if the RemoteConfig call was successful.

Note that this is only available for iOS 10 or higher.

like image 105
nikano Avatar answered Sep 28 '22 02:09

nikano


There's a fetchTimeout setting that you can use when you initialise FIRRemoteConfig.configSettings.

The documentation and details are here

like image 43
Andrea Avatar answered Sep 28 '22 02:09

Andrea