Created
August 11, 2020 18:09
-
-
Save mehmetfarhan/f59c9ec64301231259a5a259014d092a to your computer and use it in GitHub Desktop.
Firebase Remote Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Author
mehmetfarhan
commented
Aug 11, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment