ios - Swift/iOS - Firebase 远程配置在 App Delegate 中获取值
问题描述
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GADInterstitialDelegate {
//START OF CONFIGURATION
static let BANNER_ADS_ON = true
如何在 Firebase 远程配置中更改 BANNER_ADS_ON
解决方案
使用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
推荐阅读
- automation - 如何在 mailchimp 中为图像内容添加条件块?
- powershell - 使用 Powershell 打印包含制表符的 txt 文件
- java - tornadofx 中的窗口结构是什么?
- c# - 如何在例如 C# 中保护字符串
- python - 词形还原 Pandas (Python)
- ruby - 发送响应后在 sinatra 中运行代码
- wpf - WPF 数据网格 BringIntoView 行为
- r - R:如果向量构成列表的一部分,如何从向量中获取元素?
- javascript - 遍历对象循环并更改属性js
- arrays - 将 CSV ROW 组拆分为单独的 CSV 或变量