I'm using a singleton to fetch the parameters from a Firebase remote config file. The first time the app is run, I can only access the default values from the singleton; subsequent runs correctly return the config's values. What's a better way to do this, so I can access the values from a fresh start?
protocol RemoteConfigProtocol {
func remoteConfigReceived()
}
class RemoteConfigManager {
static let sharedInstance = RemoteConfigManager()
var delegate: RemoteConfigProtocol?
let demoTitle: String
// private initialiser for the singleton
private init() {
// Configure for dev mode, if needed
let remoteConfig = RemoteConfig.remoteConfig()
#if DEBUG
let expirationDuration: TimeInterval = 0
remoteConfig.configSettings = RemoteConfigSettings(developerModeEnabled: true)!
#else
let expirationDuration: TimeInterval = 3600
#endif
// default values
let appDefaults: [String: NSObject] = [
"demo_title": "Default Title" as NSObject
]
remoteConfig.setDefaults(appDefaults)
// what exactly does "activeFetched" do, then?
remoteConfig.activateFetched()
// set the values
self.demoTitle = remoteConfig["demo_title"].stringValue!
// this seems to prep app for subsequent launches
remoteConfig.fetch(withExpirationDuration: expirationDuration) { status, _ in
print("Fetch completed with status:", status, "(\(status.rawValue))")
self.delegate?.remoteConfigReceived()
}
}
}
When the asynchronous fetch
command returns in the code above (presumably with the parameter values), I am still unable to access these values coming from the config file. Only upon subsequent runs of the app are they there. Why is that? Am I missing something in my code?