Skip to content

Instantly share code, notes, and snippets.

@rabimba
Created October 19, 2016 04:54
Show Gist options
  • Save rabimba/06115afce8aef06949152b8ca3edc294 to your computer and use it in GitHub Desktop.
Save rabimba/06115afce8aef06949152b8ca3edc294 to your computer and use it in GitHub Desktop.
func fetchConfig() {
var expirationDuration: Double = 3600
// If in developer mode cacheExpiration is set to 0 so each fetch will retrieve values from
// the server.
if (self.remoteConfig.configSettings.isDeveloperModeEnabled) {
expirationDuration = 0
}
// cacheExpirationSeconds is set to cacheExpiration here, indicating that any previously
// fetched and cached config would be considered expired because it would have been fetched
// more than cacheExpiration seconds ago. Thus the next fetch would go to the server unless
// throttling is in progress. The default expiration duration is 43200 (12 hours).
remoteConfig.fetch(withExpirationDuration: expirationDuration) { (status, error) in
if (status == .success) {
print("Config fetched!")
self.remoteConfig.activateFetched()
let friendlyMsgLength = self.remoteConfig["friendly_msg_length"]
if (friendlyMsgLength.source != .static) {
self.msglength = friendlyMsgLength.numberValue!
print("Friendly msg length config: \(self.msglength)")
}
} else {
print("Config not fetched")
print("Error \(error)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment