Use Firebase Remote Config on iOS

You can use Firebase Remote Config to define parameters in your app and update their values in the cloud, allowing you to modify the appearance and behavior of your app without distributing an app update.

Add Remote Config to your app

  1. Install the Firebase SDK.
  2. Add the following dependency to your Podfile:
    pod 'Firebase/RemoteConfig'
  3. Run pod install and open the created .xcworkspace file.
  4. Import the Firebase module in your UIApplicationDelegate subclass:

    Swift

    import Firebase
    

    Objective-C

    @import Firebase;
    
  5. Configure a FirebaseApp shared instance, typically in your application's application:didFinishLaunchingWithOptions: method:

    Swift

    // Use Firebase library to configure APIs
    FirebaseApp.configure()
    

    Objective-C

    // Use Firebase library to configure APIs
    [FIRApp configure];
    
  6. Create the singleton Remote Config object, as shown in the following example:

Objective-C

self.remoteConfig = [FIRRemoteConfig remoteConfig];

Swift

self.remoteConfig = FIRRemoteConfig.remoteConfig()

This object is used to store in-app default parameter values, fetch updated parameter values from the service, and control when fetched values are made available to your app. To learn more, see Remote Config API Overview.

Set in-app default parameter values

You can set in-app default parameter values in the Remote Config object, so that your app behaves as intended before it connects to the Remote Config Server, and so that default values are available if none are set in the service.

  1. Define a set of parameter names, and default parameter values using an NSDictionary object or a plist file.
  2. Add these values to the Remote Config object using setDefaults:.

Get parameter values to use in your app

Now you can get parameter values from the Remote Config object. If you later set values in the Remote Config service, fetch them, and then activate them, those values are available to your app. Otherwise, you get the in-app parameter values configured using setDefaults:. To get these values, call the configValueForKey: method, providing the parameter key as an argument.

Connect your app in the Firebase console

In the Firebase console, add your app to your Firebase project.

Set parameter values in the service (as needed)

  1. In the Firebase console, open your project.
  2. Select Remote Config from the menu to view the Remote Config dashboard.
  3. Define parameters with the same names as the parameters that you defined in your app. For each parameter, you can set a default value (which will eventually override the in-app default value) and you can also set conditional values. To learn more, see Remote Config Parameters and Conditions.

Fetch and activate values from the service (as needed)

  1. To fetch parameter values from the Remote Config Server, call the fetchWithCompletionHandler: or fetchWithExpirationDuration:completionHandler: method. Any values that you set on the Remote Config Server are fetched and cached in the Remote Config object.
  2. To make fetched parameter values available to your app, call the activateFetched method.

Because these updated parameter values affect the behavior and appearance of your app, you should activate the fetched values at a time that ensures a smooth experience for your user, such as the next time that the user opens your app.

Send feedback about...

Need help? Visit our support page.