【问题标题】:Swift/iOS - Firebase Remote Config fetch values in App DelegateSwift/iOS - Firebase 远程配置在 App Delegate 中获取值
【发布时间】:2020-07-15 08:18:38
【问题描述】:
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GADInterstitialDelegate {
    
    //START OF CONFIGURATION

    static let BANNER_ADS_ON = true

如何在 Firebase 远程配置中更改 BANNER_ADS_ON

【问题讨论】:

    标签: ios swift firebase-remote-config


    【解决方案1】:

    使用 Firebase 远程配置 并不复杂。请阅读 Firebase 的文档和教程:https://firebase.google.com/docs/remote-config/use-config-ios#swift


    为了给你更多的想法,在你的AppDelegate,你会做这样的事情:

    private func setupRemoteConfig() {
        // Interval 1 day if prod. Otherwise 0.
        let interval: TimeInterval = ENVManager.currentEnv == .production ? (60 * 60 * 24 * 1) : 0
        
        let settings = RemoteConfigSettings()
        settings.minimumFetchInterval = interval
        
        let remoteConfig = RemoteConfig.remoteConfig()
        remoteConfig.configSettings = settings
        
        remoteConfig.fetch(withExpirationDuration: interval) { (status, error) in
            if status == .success {
                print("Config fetched!")
                remoteConfig.activate() { (error) in
                    // ...
                }
            } else {
                print("Config not fetched")
                print("Error: \(error?.localizedDescription ?? "No error available.")")
            }
        }
    }
    

    然后要访问您的值,在您的情况下是 BANNER_ADS_ON 或您想要的任何键,这样做:

    let configData = RemoteConfig.remoteConfig()["BANNER_ADS_ON"].stringValue
    

    【讨论】:

      猜你喜欢
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多