Skip to content

Instantly share code, notes, and snippets.

@mehmetfarhan
Created August 11, 2020 18:09
Show Gist options
  • Save mehmetfarhan/f59c9ec64301231259a5a259014d092a to your computer and use it in GitHub Desktop.
Save mehmetfarhan/f59c9ec64301231259a5a259014d092a to your computer and use it in GitHub Desktop.
Firebase Remote Config
import Foundation
import Firebase
struct RemoteConfigModel {
var url: String?
var forceUpdate: String?
var version: String?
}
final class RemoteConfigManager {
static var shared: RemoteConfigManager = RemoteConfigManager()
private var remoteConfig = RemoteConfig.remoteConfig()
func fetchRemoteConfig(completion: ((RemoteConfigModel?) -> ())?) {
remoteConfig.fetch(withExpirationDuration: 0) { [unowned self] (status, error) in
if status == .success {
print("Config fetched!")
self.remoteConfig.activate(completion: nil)
self.configValues(completion: completion)
} else {
print("Config not fetched")
print("Error: \(error?.localizedDescription ?? "No error available.")")
}
}
}
private func configValues(completion: ((RemoteConfigModel?) -> ())?) {
let forceUpdate = remoteConfig.configValue(forKey: "force_update").stringValue
let url = remoteConfig.configValue(forKey: "url_ios").stringValue
let version = remoteConfig.configValue(forKey: "version_ios").stringValue
let config = RemoteConfigModel(url: url, forceUpdate: forceUpdate, version: version)
completion?(config)
}
}
@mehmetfarhan
Copy link
Author

firebase
remoteConfig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment