Skip to content

Remote Config Sample App Walkthrough

Eoin Landy edited this page Jan 30, 2020 · 2 revisions

The contents of this page are based on the original Firebase Documentation

This guide walks you through the steps involved in integrating Remote Config into your AIR app.

Create a Remote Config project for the quickstart sample

The quickstart sample provides an example of using Remote Config to define the welcome message of the sample app. Before running the quickstart sample, you should set up a Remote Config project.

In the Firebase console, click Create New Project, and then follow the instructions to Set up a Firebase Remote Config Project with the following parameters:

Parameter key Default value Notes:
welcome_message Welcome to this sample app Change to use a different welcome message.
welcome_message_caps false Set to true to have the welcome message display in all caps.

How it works

First, the sample gets a Remote Config object instance and enables developer mode to allow for frequent refreshes of the cache:

remoteConfig = RemoteConfigANE.remoteConfig;
remoteConfig.configSettings = new RemoteConfigSettings(true);

Then, the sample sets in-app default values from an object:

remoteConfig.setDefaults(
        {
            "welcome_message_caps": false,
            "welcome_message": "I am a default message"
        }
);

Now, the sample creates a fetch request to fetch values from the Remote Config service and calls activateFetched to make those values available to the app:

remoteConfig.addEventListener(RemoteConfigEvent.FETCH, onRemoteConfig);

remoteConfig.fetch(expirationDuration);

Now that the welcome message has been updated, you can display the updated welcome message in the app:

private function onRemoteConfig(event:RemoteConfigEvent):void {
    remoteConfig.activateFetched();
    var message:String = remoteConfig.getString("welcome_message");
    if (remoteConfig.getBoolean("welcome_message_caps")) {
        message = message.toUpperCase();
    }
    trace(message);
}

You can access your Remote Config parameters using one of the getString, getNumber, getByteArray, or getBoolean properties.

Caching and throttling

Remote Config caches values locally after the first successful request. By default the cache expires after 12 hours, but you can change the cache expiration for a specific request by passing the desired cache expiration, in seconds, to fetch(). If the values in the cache are older than the desired cache expiration, Remote Config will request fresh config values from the service. If your app requests fresh values using fetch() several times, requests are throttled and your app is provided with a cached value.

Note: Throttling is done from within the SDK. An app can fetch a maximum of 5 times in a 60 minute window before the SDK begins to throttle and returns RemoteConfigFetchStatus.THROTTLED.

Clone this wiki locally