ios - 如何在 Firebase RemoteConfig 获取请求上添加超时?

标签 ios swift firebase timeout firebase-remote-config

我正在我的应用中使用 Firebase 远程配置功能。 我需要在获取请求上添加网络超时。

#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?()
}

我该怎么办?

最佳答案

您可以使用计时器解决此问题:

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

在这里,您将超时定义为定时器的时间间隔,一旦达到此定时器,您只需执行与 RemoteConfig 调用成功时执行的方法相同的方法。

请注意,这仅适用于 iOS 10 或更高版本。

关于ios - 如何在 Firebase RemoteConfig 获取请求上添加超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50744598/

相关文章:

ios - 导出存档以进行临时分发时无法验证位码​​ - 尝试过 Xcode 8.3.3 和 Xcode 9

ios - Objective-C 返回类型 : "-(id) init" vs "-(ClassName *) init"

ios - 如何更改 UIActivityViewController 中的文本颜色和图标颜色

ios - 未显示 UITableViewCell 中的 UILabel

firebase - Firebase WebSocket 协议(protocol)文档

android - 如何使用 Firebase 通知打开动态链接?

ios - Sprite 套件 CGPoint 未按预期工作

swift - 如何向枚举添加新案例?

macos - NSToolbarItem 无法识别的选择器发送到实例

firebase - 在 Firebase 安全规则中,您如何阻止黑客运行脚本来注册您的网站?请记住,我需要他们能够注册