cordova-plugin-firebase-config

Cordova plugin for Firebase Remote Config

Usage no npm install needed!

<script type="module">
  import cordovaPluginFirebaseConfig from 'https://cdn.skypack.dev/cordova-plugin-firebase-config';
</script>

README

Cordova plugin for Firebase Remote Config

NPM version NPM downloads NPM total downloads PayPal donate Twitter

| Donate | Your help is appreciated. Create a PR, submit a bug or just grab me :beer: | |-|-|

Index

Supported Platforms

  • iOS
  • Android

Installation

$ cordova plugin add cordova-plugin-firebase-config

Use variables IOS_FIREBASE_CONFIG_VERSION and ANDROID_FIREBASE_CONFIG_VERSION to override dependency versions for Firebase SDKs.

Preferences

You can specify FirebaseRemoteConfigDefaults in config.xml to define filename of a file with default values.

On Android the file is located at platforms/android/res/xml/${filename}.xml and has a structure like below:

<?xml version="1.0" encoding="utf-8"?>
<defaultsMap>
    <entry>
        <key>param1</key>
        <value>value1</value>
    </entry>
    <entry>
        <key>param2</key>
        <value>value2</value>
    </entry>
</defaultsMap>

On iOS file the file is located at platforms/ios/<Your App Name>/${filename}.plist and has a structure like below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>param1</key>
    <string>value1</string>
    <key>param2</key>
    <string>value2</string>
</dict>
</plist>

Methods

Every method call returns a promise which is optionally fulfilled with an appropriate value.

fetch(expirationDuration)

Starts fetching configs, adhering to the specified minimum fetch interval.

cordova.plugins.firebase.config.fetch(8 * 3600).then(function() {
    // your config was fetched
});

activate()

Asynchronously activates the most recently fetched configs, so that the fetched key value pairs take effect.

cordova.plugins.firebase.config.activate().then(function() {
    // your config was activated
});

fetchAndActivate()

Asynchronously fetches and then activates the fetched configs.

cordova.plugins.firebase.config.fetchAndActivate().then(function() {
    // your config was fetched and activated
});

getBoolean(key)

cordova.plugins.firebase.config.getBoolean("myBool").then(function(value) {
    // use value from remote config
});

getString(key)

cordova.plugins.firebase.config.getString("myStr").then(function(value) {
    // use value from remote config
});

getNumber(key)

cordova.plugins.firebase.config.getNumber("myNumber").then(function(value) {
    // use value from remote config
});

getBytes(key)

cordova.plugins.firebase.config.getBytes("myByteArray").then(function(value) {
    // use value from remote config
});

getValueSource(key)

Returns source of the value for the specified key. Possible values: | Constant | Value | Description | | :-- | :-- | :-- | | VALUE_SOURCE_STATIC | 0 | Indicates that the value returned is the static default value. | | VALUE_SOURCE_DEFAULT | 1 | Indicates that the value returned was retrieved from the defaults set by the client. | | VALUE_SOURCE_REMOTE | 2 | Indicates that the value returned was retrieved from the Firebase Remote Config Server. |

cordova.plugins.firebase.config.getValueSource("myArbitraryValue").then(function(source) {
    if (source === cordova.plugins.firebase.config.VALUE_SOURCE_DEFAULT) {
        //...
    }
});