8.0.0 • Published 6 months ago

cordova-plugin-firebase-config v8.0.0

Weekly downloads
362
License
MIT
Repository
github
Last release
6 months ago

Cordova plugin for Firebase Remote Config

NPM version NPM downloads NPM total downloads PayPal donate Twitter

DonateYour 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_POD_VERSION and ANDROID_FIREBASE_BOM_VERSION to override dependency versions for Firebase SDKs:

$ cordova plugin add cordova-plugin-firebase-config \
--variable IOS_FIREBASE_POD_VERSION="9.3.0" \
--variable ANDROID_FIREBASE_BOM_VERSION="30.3.1"

Adding required configuration files

Cordova supports resource-file tag for easy copying resources files. Firebase SDK requires google-services.json on Android and GoogleService-Info.plist on iOS platforms.

  1. Put google-services.json and/or GoogleService-Info.plist into the root directory of your Cordova project
  2. Add new tag for Android platform
<platform name="android">
    ...
    <resource-file src="google-services.json" target="app/google-services.json" />
</platform>
...
<platform name="ios">
    ...
    <resource-file src="GoogleService-Info.plist" />
</platform>

Preferences

You can specify FirebaseRemoteConfigDefaults in config.xml to define filename of a file with default values. Keep in mind that android and ios have different naming convensions there it's useful to specify different file names.

<platform name="android">
    ...
    <preference name="FirebaseRemoteConfigDefaults" value="remote_config_defaults" />
    <resource-file src="resources/android/remote_config_defaults.xml" target="app/src/main/res/xml/remote_config_defaults.xml" />
</platform>

<platform name="ios">
    ...
    <preference name="FirebaseRemoteConfigDefaults" value="RemoteConfigDefaults" />
    <resource-file src="resources/ios/RemoteConfigDefaults.plist" />
</platform>

On Android platform file remote_config_defaults.xml 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 platform file RemoteConfigDefaults.plist 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>

Variables

VALUE_SOURCE_DEFAULT

VALUE_SOURCE_DEFAULT: number

Indicates that the value returned was retrieved from the defaults set by the client.

Constant


VALUE_SOURCE_REMOTE

VALUE_SOURCE_REMOTE: number

Indicates that the value returned was retrieved from the Firebase Remote Config Server.

Constant


VALUE_SOURCE_STATIC

VALUE_SOURCE_STATIC: number

Indicates that the value returned is the static default value.

Constant

Functions

activate

activate(): Promise<boolean>

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

Example

cordova.plugins.firebase.config.activate();

Returns

Promise<boolean>

Fulfills promise with flag if current config was activated


fetch

fetch(expirationDuration): Promise<void>

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

Example

cordova.plugins.firebase.config.fetch(8 * 3600);

Parameters

NameTypeDescription
expirationDurationnumberMinimum fetch interval in seconds

Returns

Promise<void>

Callback when operation is completed


fetchAndActivate

fetchAndActivate(): Promise<boolean>

Asynchronously fetches and then activates the fetched configs.

Example

cordova.plugins.firebase.config.fetchAndActivate();

Returns

Promise<boolean>

Fulfills promise with flag if current config was activated


getBoolean

getBoolean(key): Promise<boolean>

Returns the boolean parameter value for the given key

Example

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

Parameters

NameTypeDescription
keystringParameter key

Returns

Promise<boolean>

Fulfills promise with parameter value


getBytes

getBytes(key): Promise<ArrayBuffer>

Returns the bytes parameter value for the given key

Example

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

Parameters

NameTypeDescription
keystringParameter key

Returns

Promise<ArrayBuffer>

Fulfills promise with parameter value


getNumber

getNumber(key): Promise<number>

Returns the number parameter value for the given key

Example

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

Parameters

NameTypeDescription
keystringParameter key

Returns

Promise<number>

Fulfills promise with parameter value


getString

getString(key): Promise<string>

Returns the string parameter value for the given key

Example

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

Parameters

NameTypeDescription
keystringParameter key

Returns

Promise<string>

Fulfills promise with parameter value


getValueSource

getValueSource(key): Promise<number>

Returns source of the value for the specified key.

Example

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

Parameters

NameTypeDescription
keystringParameter key

Returns

Promise<number>

Fulfills promise with parameter value

8.0.0

6 months ago

7.0.3

2 years ago

7.0.0

2 years ago

7.0.2

2 years ago

7.0.1

2 years ago

6.1.0

2 years ago

6.0.0

3 years ago

5.1.0

3 years ago

5.0.0

3 years ago

4.5.0

4 years ago

4.4.1

4 years ago

4.4.0

4 years ago

4.3.0

4 years ago

4.2.0

4 years ago

4.1.0

4 years ago

4.0.1

4 years ago

4.0.0

5 years ago

3.0.0

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

6 years ago

0.12.0

6 years ago

0.11.2

6 years ago

0.11.1

6 years ago

0.11.0

6 years ago

0.10.3

6 years ago

0.10.2

7 years ago

0.10.1

7 years ago