RemoteConfig
class RemoteConfig : NSObject, NSFastEnumeration
Firebase Remote Config class. The class method remoteConfig()
can be used
to fetch, activate and read config results and set default config results on the default
Remote Config instance.
-
Last successful fetch completion time.
Declaration
Swift
var lastFetchTime: Date? { get }
-
Last fetch status. The status can be any enumerated value from
RemoteConfigFetchStatus
.Declaration
Swift
var lastFetchStatus: RemoteConfigFetchStatus { get }
-
Config settings are custom settings.
Declaration
Swift
var configSettings: RemoteConfigSettings { get set }
-
Returns the
RemoteConfig
instance configured for the default Firebase app. This singleton object contains the complete set of Remote Config parameter values available to the app, including the Active Config and Default Config. This object also caches values fetched from the Remote Config server until they are copied to the Active Config by callingactivate()
. When you fetch values from the Remote Config server using the default Firebase app, you should use this class method to create and reuse a shared instance ofRemoteConfig
.Declaration
Swift
class func remoteConfig() -> RemoteConfig
-
Returns the
RemoteConfig
instance for your (non-default) Firebase appID. Note that Firebase analytics does not work for non-default app instances. This singleton object contains the complete set of Remote Config parameter values available to the app, including the Active Config and Default Config. This object also caches values fetched from the Remote Config Server until they are copied to the Active Config by callingactivate())
. When you fetch values from the Remote Config Server using the non-default Firebase app, you should use this class method to create and reuse shared instance ofRemoteConfig
.Declaration
Swift
class func remoteConfig(app: FIRApp) -> RemoteConfig
-
Unavailable
Use +remoteConfig instead.
Unavailable. Use +remoteConfig instead.
-
Ensures initialization is complete and clients can begin querying for Remote Config values.
Declaration
Swift
func ensureInitialized() async throws
Parameters
completionHandler
Initialization complete callback with error parameter.
-
Fetches Remote Config data with a callback. Call
activate()
to make fetched data available to your app.Note: This method uses a Firebase Installations token to identify the app instance, and once it’s called, it periodically sends data to the Firebase backend. (see
Installations.authToken(completion:)
). To stop the periodic sync, callInstallations.delete(completion:)
and avoid calling this method again.Declaration
Swift
func fetch() async throws -> RemoteConfigFetchStatus
Parameters
completionHandler
Fetch operation callback with status and error parameters.
-
Fetches Remote Config data and sets a duration that specifies how long config data lasts. Call
activateWithCompletion:
to make fetched data available to your app.Note: This method uses a Firebase Installations token to identify the app instance, and once it’s called, it periodically sends data to the Firebase backend. (see
Installations.authToken(completion:)
). To stop the periodic sync, callInstallations.delete(completion:)
and avoid calling this method again.Declaration
Swift
func fetch(withExpirationDuration expirationDuration: TimeInterval) async throws -> RemoteConfigFetchStatus
Parameters
expirationDuration
Override the (default or optionally set
minimumFetchInterval
property in RemoteConfigSettings)minimumFetchInterval
for only the current request, in seconds. Setting a value of 0 seconds will force a fetch to the backend.completionHandler
Fetch operation callback with status and error parameters.
-
Fetches Remote Config data and if successful, activates fetched data. Optional completion handler callback is invoked after the attempted activation of data, if the fetch call succeeded.
Note: This method uses a Firebase Installations token to identify the app instance, and once it’s called, it periodically sends data to the Firebase backend. (see
Installations.authToken(completion:)
). To stop the periodic sync, callInstallations.delete(completion:)
and avoid calling this method again.Declaration
Swift
func fetchAndActivate() async throws -> RemoteConfigFetchAndActivateStatus
Parameters
completionHandler
Fetch operation callback with status and error parameters.
-
Applies Fetched Config data to the Active Config, causing updates to the behavior and appearance of the app to take effect (depending on how config data is used in the app).
Declaration
Swift
func activate() async throws -> Bool
Parameters
completion
Activate operation callback with changed and error parameters.
-
Enables access to configuration values by using object subscripting syntax. For example: let config = RemoteConfig.remoteConfig() let value = config[“yourKey”] let boolValue = value.boolValue let number = config[“yourKey”].numberValue
Declaration
Swift
subscript(key: String) -> RemoteConfigValue { get }
-
Gets the config value.
Declaration
Swift
func configValue(forKey key: String?) -> RemoteConfigValue
Parameters
key
Config key.
-
Gets the config value of a given source from the default namespace.
Declaration
Swift
func configValue(forKey key: String?, source: RemoteConfigSource) -> RemoteConfigValue
Parameters
key
Config key.
source
Config value source.
-
Gets all the parameter keys of a given source from the default namespace.
Declaration
Swift
func allKeys(from source: RemoteConfigSource) -> [String]
Parameters
source
The config data source.
Return Value
An array of keys under the given source.
-
Returns the set of parameter keys that start with the given prefix, from the default namespace in the active config.
Declaration
Swift
func keys(withPrefix prefix: String?) -> Set<String>
Parameters
prefix
The key prefix to look for. If prefix is nil or empty, returns all the keys.
Return Value
The set of parameter keys that start with the specified prefix.
-
Sets config defaults for parameter keys and values in the default namespace config.
Declaration
Swift
func setDefaults(_ defaults: [String : NSObject]?)
Parameters
defaults
A dictionary mapping a NSString * key to a NSObject * value.
-
Sets default configs from plist for default namespace.
Declaration
Swift
func setDefaults(fromPlist fileName: String?)
Parameters
fileName
The plist file name, with no file name extension. For example, if the plist file is named
defaultSamples.plist
:RemoteConfig.remoteConfig().setDefaults(fromPlist: "defaultSamples")
-
Returns the default value of a given key from the default config.
Declaration
Swift
func defaultValue(forKey key: String?) -> RemoteConfigValue?
Parameters
key
The parameter key of default config.
Return Value
Returns the default value of the specified key. Returns nil if the key doesn’t exist in the default config.
-
Start listening for real-time config updates from the Remote Config backend and automatically fetch updates when they’re available.
If a connection to the Remote Config backend is not already open, calling this method will open it. Multiple listeners can be added by calling this method again, but subsequent calls re-use the same connection to the backend.
Note: Real-time Remote Config requires the Firebase Remote Config Realtime API. See Get started with Firebase Remote Config at https://firebase.google.com/docs/remote-config/get-started for more information.
Declaration
Swift
func addOnConfigUpdateListener(remoteConfigUpdateCompletion listener: @escaping (RemoteConfigUpdate?, (any Error)?) -> Void) -> ConfigUpdateListenerRegistration
Parameters
listener
The configured listener that is called for every config update.
Return Value
Returns a registration representing the listener. The registration contains a remove method, which can be used to stop receiving updates for the provided listener.
-
Decodes a struct from the respective Remote Config values.
Declaration
Swift
func decoded<Value>(asType: Value.Type = Value.self) throws -> Value where Value : Decodable
Parameters
asType
The type to decode to.
-
Sets config defaults from an encodable struct.
Declaration
Swift
func setDefaults<Value>(from value: Value) throws where Value : Encodable
Parameters
value
The object to use to set the defaults.
-
Return a typed RemoteConfigValue for a key.
Declaration
Swift
subscript<T>(decodedValue key: String) -> T? where T : Decodable { get }
Parameters
key
A Remote Config key.
Return Value
A typed RemoteConfigValue.
-
Return a Dictionary for a RemoteConfig JSON key.
Declaration
Swift
subscript(jsonValue key: String) -> [String : AnyHashable]? { get }
Parameters
key
A Remote Config key.
Return Value
A Dictionary representing a RemoteConfig JSON value.