├── .github └── FUNDING.yml ├── types ├── index.d.ts └── FirebaseConfig.d.ts ├── tsconfig.json ├── src ├── ios │ ├── FirebaseConfigPlugin.h │ └── FirebaseConfigPlugin.m └── android │ └── FirebaseConfigPlugin.java ├── LICENSE ├── .gitignore ├── package.json ├── plugin.xml ├── www └── FirebaseConfig.js └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YYRKVZJSHLTNC&source=url 4 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | interface CordovaPlugins { 2 | firebase: FirebasePlugins; 3 | } 4 | 5 | interface FirebasePlugins { 6 | config: typeof import("./FirebaseConfig"); 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "typedocOptions": { 3 | "out": "docs", 4 | "readme": "none", 5 | "entryPoints": "./types", 6 | "exclude": "./types/index.d.ts", 7 | "entryPointStrategy": "expand", 8 | "hideBreadcrumbs": true, 9 | "hideInPageTOC": true, 10 | "hidePageTitle": true, 11 | "hideMembersSymbol": true, 12 | "disableSources": true, 13 | "githubPages": false 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/ios/FirebaseConfigPlugin.h: -------------------------------------------------------------------------------- 1 | #import 2 | @import FirebaseRemoteConfig; 3 | 4 | @interface FirebaseConfigPlugin : CDVPlugin 5 | 6 | - (void)fetch:(CDVInvokedUrlCommand*)command; 7 | - (void)activate:(CDVInvokedUrlCommand*)command; 8 | - (void)fetchAndActivate:(CDVInvokedUrlCommand*)command; 9 | - (void)getString:(CDVInvokedUrlCommand*)command; 10 | - (void)getNumber:(CDVInvokedUrlCommand*)command; 11 | - (void)getBoolean:(CDVInvokedUrlCommand*)command; 12 | - (void)getBytes:(CDVInvokedUrlCommand*)command; 13 | - (void)getValueSource:(CDVInvokedUrlCommand*)command; 14 | 15 | @property (nonatomic, strong) FIRRemoteConfig *remoteConfig; 16 | @end 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Maksim Chemerisuk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | /docs 60 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-plugin-firebase-config", 3 | "version": "8.0.0", 4 | "description": "Cordova plugin for Firebase Remote Config", 5 | "types": "./types/index.d.ts", 6 | "cordova": { 7 | "id": "cordova-plugin-firebase-config", 8 | "platforms": [ 9 | "ios", 10 | "android" 11 | ] 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/chemerisuk/cordova-plugin-firebase-config.git" 16 | }, 17 | "author": "Maksim Chemerisuk (https://github.com/chemerisuk)", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/chemerisuk/cordova-plugin-firebase-config/issues" 21 | }, 22 | "homepage": "https://github.com/chemerisuk/cordova-plugin-firebase-config#readme", 23 | "funding": "https://github.com/chemerisuk/cordova-plugin-firebase-config?sponsor=1", 24 | "keywords": [ 25 | "cordova", 26 | "firebase", 27 | "remote config", 28 | "analytics", 29 | "ecosystem:cordova", 30 | "cordova-android", 31 | "cordova-ios" 32 | ], 33 | "scripts": { 34 | "preversion": "npm run docs && rm -rf docs", 35 | "version": "perl -i -pe 's/(version=)\"\\d+\\.\\d+\\.\\d+\"/$1\"'$npm_package_version'\"$2/' plugin.xml && git add .", 36 | "postversion": "git push && git push --tags", 37 | "predocs": "tsc www/* --declaration --allowJs --checkJs --lib es2015,dom --emitDeclarationOnly --outDir types", 38 | "docs": "typedoc && perl -i -pe 's/README.md#/#/g' ./docs/README.md", 39 | "postdocs": "perl -i -0pe 's/().*/$1\n\n/gms' README.md && cat ./docs/README.md >> README.md" 40 | }, 41 | "devDependencies": { 42 | "typedoc": "^0.23.9", 43 | "typedoc-plugin-markdown": "^3.13.4" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | cordova-plugin-firebase-config 7 | Cordova plugin for Firebase Remote Config 8 | MIT 9 | cordova 10 | https://github.com/chemerisuk/cordova-plugin-firebase-config 11 | https://github.com/chemerisuk/cordova-plugin-firebase-config/issues 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /types/FirebaseConfig.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Starts fetching configs, adhering to the specified minimum fetch interval. 4 | * @param {number} expirationDuration Minimum fetch interval in seconds 5 | * @returns {Promise} Callback when operation is completed 6 | * 7 | * @example 8 | * cordova.plugins.firebase.config.fetch(8 * 3600); 9 | */ 10 | export function fetch(expirationDuration: number): Promise; 11 | /** 12 | * 13 | * Asynchronously activates the most recently fetched configs, so that the fetched key value pairs take effect. 14 | * @returns {Promise} Fulfills promise with flag if current config was activated 15 | * 16 | * @example 17 | * cordova.plugins.firebase.config.activate(); 18 | */ 19 | export function activate(): Promise; 20 | /** 21 | * 22 | * Asynchronously fetches and then activates the fetched configs. 23 | * @returns {Promise} Fulfills promise with flag if current config was activated 24 | * 25 | * @example 26 | * cordova.plugins.firebase.config.fetchAndActivate(); 27 | */ 28 | export function fetchAndActivate(): Promise; 29 | /** 30 | * 31 | * Returns the boolean parameter value for the given key 32 | * @param {string} key Parameter key 33 | * @returns {Promise} Fulfills promise with parameter value 34 | * 35 | * @example 36 | * cordova.plugins.firebase.config.getBoolean("myBool").then(function(value) { 37 | * // use value from remote config 38 | * }); 39 | */ 40 | export function getBoolean(key: string): Promise; 41 | /** 42 | * 43 | * Returns the string parameter value for the given key 44 | * @param {string} key Parameter key 45 | * @returns {Promise} Fulfills promise with parameter value 46 | * 47 | * @example 48 | * cordova.plugins.firebase.config.getString("myStr").then(function(value) { 49 | * // use value from remote config 50 | * }); 51 | */ 52 | export function getString(key: string): Promise; 53 | /** 54 | * 55 | * Returns the number parameter value for the given key 56 | * @param {string} key Parameter key 57 | * @returns {Promise} Fulfills promise with parameter value 58 | * 59 | * @example 60 | * cordova.plugins.firebase.config.getNumber("myNumber").then(function(value) { 61 | * // use value from remote config 62 | * }); 63 | */ 64 | export function getNumber(key: string): Promise; 65 | /** 66 | * 67 | * Returns the bytes parameter value for the given key 68 | * @param {string} key Parameter key 69 | * @returns {Promise} Fulfills promise with parameter value 70 | * 71 | * @example 72 | * cordova.plugins.firebase.config.getBytes("myByteArray").then(function(value) { 73 | * // use value from remote config 74 | * }); 75 | */ 76 | export function getBytes(key: string): Promise; 77 | /** 78 | * 79 | * Returns source of the value for the specified key. 80 | * @param {string} key Parameter key 81 | * @returns {Promise} Fulfills promise with parameter value 82 | * 83 | * @example 84 | * cordova.plugins.firebase.config.getValueSource("myArbitraryValue").then(function(source) { 85 | * if (source === cordova.plugins.firebase.config.VALUE_SOURCE_DEFAULT) { 86 | * // ... 87 | * } 88 | * }); 89 | */ 90 | export function getValueSource(key: string): Promise; 91 | /** 92 | * Indicates that the value returned is the static default value. 93 | * @type {number} 94 | * @constant 95 | */ 96 | export var VALUE_SOURCE_STATIC: number; 97 | /** 98 | * Indicates that the value returned was retrieved from the defaults set by the client. 99 | * @type {number} 100 | * @constant 101 | */ 102 | export var VALUE_SOURCE_DEFAULT: number; 103 | /** 104 | * Indicates that the value returned was retrieved from the Firebase Remote Config Server. 105 | * @type {number} 106 | * @constant 107 | */ 108 | export var VALUE_SOURCE_REMOTE: number; 109 | -------------------------------------------------------------------------------- /src/android/FirebaseConfigPlugin.java: -------------------------------------------------------------------------------- 1 | package by.chemerisuk.cordova.firebase; 2 | 3 | import static com.google.android.gms.tasks.Tasks.await; 4 | import static by.chemerisuk.cordova.support.ExecutionThread.WORKER; 5 | 6 | import java.util.Collections; 7 | 8 | import android.content.Context; 9 | import android.util.Log; 10 | 11 | import by.chemerisuk.cordova.support.CordovaMethod; 12 | import by.chemerisuk.cordova.support.ReflectiveCordovaPlugin; 13 | 14 | import com.google.firebase.remoteconfig.FirebaseRemoteConfig; 15 | import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue; 16 | 17 | import org.apache.cordova.CallbackContext; 18 | import org.apache.cordova.CordovaArgs; 19 | import org.apache.cordova.PluginResult; 20 | import org.json.JSONException; 21 | 22 | 23 | public class FirebaseConfigPlugin extends ReflectiveCordovaPlugin { 24 | private static final String TAG = "FirebaseConfigPlugin"; 25 | 26 | private FirebaseRemoteConfig firebaseRemoteConfig; 27 | 28 | @Override 29 | protected void pluginInitialize() { 30 | Log.d(TAG, "Starting Firebase Remote Config plugin"); 31 | 32 | firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); 33 | 34 | String filename = preferences.getString("FirebaseRemoteConfigDefaults", ""); 35 | if (filename.isEmpty()) { 36 | // always call setDefaults in order to avoid exception 37 | // https://github.com/firebase/quickstart-android/issues/291 38 | firebaseRemoteConfig.setDefaultsAsync(Collections.emptyMap()); 39 | } else { 40 | Context ctx = cordova.getActivity().getApplicationContext(); 41 | int resourceId = ctx.getResources().getIdentifier(filename, "xml", ctx.getPackageName()); 42 | firebaseRemoteConfig.setDefaultsAsync(resourceId); 43 | } 44 | } 45 | 46 | @CordovaMethod(WORKER) 47 | protected void fetch(CordovaArgs args, CallbackContext callbackContext) throws Exception { 48 | long expirationDuration = args.getLong(0); 49 | await(firebaseRemoteConfig.fetch(expirationDuration)); 50 | callbackContext.success(); 51 | } 52 | 53 | @CordovaMethod(WORKER) 54 | protected void activate(CallbackContext callbackContext) throws Exception { 55 | boolean activated = await(firebaseRemoteConfig.activate()); 56 | callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, activated)); 57 | } 58 | 59 | @CordovaMethod(WORKER) 60 | protected void fetchAndActivate(CallbackContext callbackContext) throws Exception { 61 | boolean activated = await(firebaseRemoteConfig.fetchAndActivate()); 62 | callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, activated)); 63 | } 64 | 65 | @CordovaMethod 66 | protected void getBoolean(CordovaArgs args, CallbackContext callbackContext) throws JSONException { 67 | String key = args.getString(0); 68 | callbackContext.sendPluginResult( 69 | new PluginResult(PluginResult.Status.OK, getValue(key).asBoolean())); 70 | } 71 | 72 | @CordovaMethod 73 | protected void getBytes(CordovaArgs args, CallbackContext callbackContext) throws JSONException { 74 | String key = args.getString(0); 75 | callbackContext.success(getValue(key).asByteArray()); 76 | } 77 | 78 | @CordovaMethod 79 | protected void getNumber(CordovaArgs args, CallbackContext callbackContext) throws JSONException { 80 | String key = args.getString(0); 81 | callbackContext.sendPluginResult( 82 | new PluginResult(PluginResult.Status.OK, (float)getValue(key).asDouble())); 83 | } 84 | 85 | @CordovaMethod 86 | protected void getString(CordovaArgs args, CallbackContext callbackContext) throws JSONException { 87 | String key = args.getString(0); 88 | callbackContext.success(getValue(key).asString()); 89 | } 90 | 91 | @CordovaMethod 92 | protected void getValueSource(CordovaArgs args, CallbackContext callbackContext) throws JSONException { 93 | String key = args.getString(0); 94 | callbackContext.success(getValue(key).getSource()); 95 | } 96 | 97 | private FirebaseRemoteConfigValue getValue(String key) { 98 | return firebaseRemoteConfig.getValue(key); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /www/FirebaseConfig.js: -------------------------------------------------------------------------------- 1 | var PLUGIN_NAME = "FirebaseConfig"; 2 | // @ts-ignore 3 | var exec = require("cordova/exec"); 4 | 5 | function promiseParameter(type, key) { 6 | return new Promise(function(resolve, reject) { 7 | exec(resolve, reject, PLUGIN_NAME, "get" + type, [key || ""]); 8 | }); 9 | } 10 | 11 | exports.fetch = 12 | /** 13 | * 14 | * Starts fetching configs, adhering to the specified minimum fetch interval. 15 | * @param {number} expirationDuration Minimum fetch interval in seconds 16 | * @returns {Promise} Callback when operation is completed 17 | * 18 | * @example 19 | * cordova.plugins.firebase.config.fetch(8 * 3600); 20 | */ 21 | function(expirationDuration) { 22 | return new Promise(function(resolve, reject) { 23 | exec(resolve, reject, PLUGIN_NAME, "fetch", [expirationDuration || 0]); 24 | }); 25 | }; 26 | 27 | exports.activate = 28 | /** 29 | * 30 | * Asynchronously activates the most recently fetched configs, so that the fetched key value pairs take effect. 31 | * @returns {Promise} Fulfills promise with flag if current config was activated 32 | * 33 | * @example 34 | * cordova.plugins.firebase.config.activate(); 35 | */ 36 | function() { 37 | return new Promise(function(resolve, reject) { 38 | exec(resolve, reject, PLUGIN_NAME, "activate", []); 39 | }); 40 | }; 41 | 42 | exports.fetchAndActivate = 43 | /** 44 | * 45 | * Asynchronously fetches and then activates the fetched configs. 46 | * @returns {Promise} Fulfills promise with flag if current config was activated 47 | * 48 | * @example 49 | * cordova.plugins.firebase.config.fetchAndActivate(); 50 | */ 51 | function() { 52 | return new Promise(function(resolve, reject) { 53 | exec(resolve, reject, PLUGIN_NAME, "activate", []); 54 | }); 55 | }; 56 | 57 | exports.getBoolean = 58 | /** 59 | * 60 | * Returns the boolean parameter value for the given key 61 | * @param {string} key Parameter key 62 | * @returns {Promise} Fulfills promise with parameter value 63 | * 64 | * @example 65 | * cordova.plugins.firebase.config.getBoolean("myBool").then(function(value) { 66 | * // use value from remote config 67 | * }); 68 | */ 69 | function(key) { 70 | return promiseParameter("Boolean", key); 71 | }; 72 | 73 | exports.getString = 74 | /** 75 | * 76 | * Returns the string parameter value for the given key 77 | * @param {string} key Parameter key 78 | * @returns {Promise} Fulfills promise with parameter value 79 | * 80 | * @example 81 | * cordova.plugins.firebase.config.getString("myStr").then(function(value) { 82 | * // use value from remote config 83 | * }); 84 | */ 85 | function(key) { 86 | return promiseParameter("String", key); 87 | }; 88 | 89 | exports.getNumber = 90 | /** 91 | * 92 | * Returns the number parameter value for the given key 93 | * @param {string} key Parameter key 94 | * @returns {Promise} Fulfills promise with parameter value 95 | * 96 | * @example 97 | * cordova.plugins.firebase.config.getNumber("myNumber").then(function(value) { 98 | * // use value from remote config 99 | * }); 100 | */ 101 | function(key) { 102 | return promiseParameter("Number", key); 103 | }; 104 | 105 | exports.getBytes = 106 | /** 107 | * 108 | * Returns the bytes parameter value for the given key 109 | * @param {string} key Parameter key 110 | * @returns {Promise} Fulfills promise with parameter value 111 | * 112 | * @example 113 | * cordova.plugins.firebase.config.getBytes("myByteArray").then(function(value) { 114 | * // use value from remote config 115 | * }); 116 | */ 117 | function(key) { 118 | return promiseParameter("Bytes", key); 119 | }; 120 | 121 | exports.getValueSource = 122 | /** 123 | * 124 | * Returns source of the value for the specified key. 125 | * @param {string} key Parameter key 126 | * @returns {Promise} Fulfills promise with parameter value 127 | * 128 | * @example 129 | * cordova.plugins.firebase.config.getValueSource("myArbitraryValue").then(function(source) { 130 | * if (source === cordova.plugins.firebase.config.VALUE_SOURCE_DEFAULT) { 131 | * // ... 132 | * } 133 | * }); 134 | */ 135 | function(key) { 136 | return promiseParameter("ValueSource", key); 137 | }; 138 | 139 | /** 140 | * Indicates that the value returned is the static default value. 141 | * @type {number} 142 | * @constant 143 | */ 144 | var VALUE_SOURCE_STATIC = 0; 145 | /** 146 | * Indicates that the value returned was retrieved from the defaults set by the client. 147 | * @type {number} 148 | * @constant 149 | */ 150 | var VALUE_SOURCE_DEFAULT = 1; 151 | /** 152 | * Indicates that the value returned was retrieved from the Firebase Remote Config Server. 153 | * @type {number} 154 | * @constant 155 | */ 156 | var VALUE_SOURCE_REMOTE = 2; 157 | 158 | exports.VALUE_SOURCE_STATIC = VALUE_SOURCE_STATIC; 159 | exports.VALUE_SOURCE_DEFAULT = VALUE_SOURCE_DEFAULT; 160 | exports.VALUE_SOURCE_REMOTE = VALUE_SOURCE_REMOTE; 161 | -------------------------------------------------------------------------------- /src/ios/FirebaseConfigPlugin.m: -------------------------------------------------------------------------------- 1 | #import "FirebaseConfigPlugin.h" 2 | @import FirebaseCore; 3 | 4 | @implementation FirebaseConfigPlugin 5 | 6 | static const int VALUE_SOURCE_STATIC = 0; 7 | static const int VALUE_SOURCE_DEFAULT = 1; 8 | static const int VALUE_SOURCE_REMOTE = 2; 9 | 10 | - (void)pluginInitialize { 11 | NSLog(@"Starting Firebase Remote Config plugin"); 12 | 13 | if (![FIRApp defaultApp]) { 14 | [FIRApp configure]; 15 | } 16 | 17 | self.remoteConfig = [FIRRemoteConfig remoteConfig]; 18 | NSString* plistFilename = [self.commandDelegate.settings objectForKey:[@"FirebaseRemoteConfigDefaults" lowercaseString]]; 19 | if (plistFilename) { 20 | [self.remoteConfig setDefaultsFromPlistFileName:plistFilename]; 21 | } 22 | } 23 | 24 | - (void)fetch:(CDVInvokedUrlCommand *)command { 25 | long expirationDuration = [[command argumentAtIndex:0] longValue]; 26 | 27 | [self.remoteConfig fetchWithExpirationDuration:expirationDuration completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *err) { 28 | CDVPluginResult *pluginResult = nil; 29 | if (err) { 30 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:err.localizedDescription]; 31 | } else { 32 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; 33 | } 34 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 35 | }]; 36 | } 37 | 38 | - (void)activate:(CDVInvokedUrlCommand *)command { 39 | [self.remoteConfig activateWithCompletion:^(BOOL changed, NSError * _Nullable err) { 40 | CDVPluginResult *pluginResult = nil; 41 | if (err) { 42 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:err.localizedDescription]; 43 | } else { 44 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:changed]; 45 | } 46 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 47 | }]; 48 | } 49 | 50 | - (void)fetchAndActivate:(CDVInvokedUrlCommand *)command { 51 | [self.remoteConfig fetchAndActivateWithCompletionHandler:^(FIRRemoteConfigFetchAndActivateStatus status, NSError * _Nullable err) { 52 | CDVPluginResult *pluginResult = nil; 53 | if (err) { 54 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:err.localizedDescription]; 55 | } else { 56 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool: 57 | (status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote)]; 58 | } 59 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 60 | }]; 61 | } 62 | 63 | - (void)getString:(CDVInvokedUrlCommand *)command { 64 | FIRRemoteConfigValue *configValue = [self getConfigValue:command]; 65 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK 66 | messageAsString:configValue.stringValue]; 67 | 68 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 69 | } 70 | 71 | - (void)getNumber:(CDVInvokedUrlCommand *)command { 72 | FIRRemoteConfigValue *configValue = [self getConfigValue:command]; 73 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK 74 | messageAsDouble:[configValue.numberValue doubleValue]]; 75 | 76 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 77 | } 78 | 79 | - (void)getBoolean:(CDVInvokedUrlCommand *)command { 80 | FIRRemoteConfigValue *configValue = [self getConfigValue:command]; 81 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK 82 | messageAsBool:configValue.boolValue]; 83 | 84 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 85 | } 86 | 87 | - (void)getBytes:(CDVInvokedUrlCommand *)command { 88 | FIRRemoteConfigValue *configValue = [self getConfigValue:command]; 89 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK 90 | messageAsArrayBuffer:configValue.dataValue]; 91 | 92 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 93 | } 94 | 95 | - (void)getValueSource:(CDVInvokedUrlCommand*)command { 96 | FIRRemoteConfigValue *configValue = [self getConfigValue:command]; 97 | 98 | CDVPluginResult *pluginResult = [CDVPluginResult 99 | resultWithStatus:CDVCommandStatus_OK 100 | messageAsInt:convertFIRRemoteConfigSourceToPluginResult(configValue.source)]; 101 | 102 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 103 | } 104 | 105 | int convertFIRRemoteConfigSourceToPluginResult(FIRRemoteConfigSource value) { 106 | switch (value) { 107 | case FIRRemoteConfigSourceDefault: 108 | return VALUE_SOURCE_DEFAULT; 109 | case FIRRemoteConfigSourceRemote: 110 | return VALUE_SOURCE_REMOTE; 111 | case FIRRemoteConfigSourceStatic: 112 | return VALUE_SOURCE_STATIC; 113 | default: 114 | return VALUE_SOURCE_STATIC; 115 | } 116 | } 117 | 118 | - (FIRRemoteConfigValue*)getConfigValue:(CDVInvokedUrlCommand *)command { 119 | NSString* key = [command argumentAtIndex:0]; 120 | 121 | return [self.remoteConfig configValueForKey:key]; 122 | } 123 | 124 | 125 | @end 126 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cordova plugin for [Firebase Remote Config](https://firebase.google.com/docs/remote-config/) 2 | 3 | [![NPM version][npm-version]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![NPM total downloads][npm-total-downloads]][npm-url] [![PayPal donate](https://img.shields.io/badge/paypal-donate-ff69b4?logo=paypal)][donate-url] [![Twitter][twitter-follow]][twitter-url] 4 | 5 | | [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)][donate-url] | Your help is appreciated. Create a PR, submit a bug or just grab me :beer: | 6 | |-|-| 7 | 8 | [npm-url]: https://www.npmjs.com/package/cordova-plugin-firebase-config 9 | [npm-version]: https://img.shields.io/npm/v/cordova-plugin-firebase-config.svg 10 | [npm-downloads]: https://img.shields.io/npm/dm/cordova-plugin-firebase-config.svg 11 | [npm-total-downloads]: https://img.shields.io/npm/dt/cordova-plugin-firebase-config.svg?label=total+downloads 12 | [twitter-url]: https://twitter.com/chemerisuk 13 | [twitter-follow]: https://img.shields.io/twitter/follow/chemerisuk.svg?style=social&label=Follow%20me 14 | [donate-url]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YYRKVZJSHLTNC&source=url 15 | 16 | ## Index 17 | 18 | 19 | 20 | - [Supported Platforms](#supported-platforms) 21 | - [Installation](#installation) 22 | - [Adding required configuration files](#adding-required-configuration-files) 23 | - [Preferences](#preferences) 24 | - [Variables](#variables) 25 | - [VALUE\_SOURCE\_DEFAULT](#value_source_default) 26 | - [VALUE\_SOURCE\_REMOTE](#value_source_remote) 27 | - [VALUE\_SOURCE\_STATIC](#value_source_static) 28 | - [Functions](#functions) 29 | - [activate](#activate) 30 | - [fetch](#fetch) 31 | - [fetchAndActivate](#fetchandactivate) 32 | - [getBoolean](#getboolean) 33 | - [getBytes](#getbytes) 34 | - [getNumber](#getnumber) 35 | - [getString](#getstring) 36 | - [getValueSource](#getvaluesource) 37 | 38 | 39 | 40 | ## Supported Platforms 41 | 42 | - iOS 43 | - Android 44 | 45 | ## Installation 46 | 47 | $ cordova plugin add cordova-plugin-firebase-config 48 | 49 | Use variables `IOS_FIREBASE_POD_VERSION` and `ANDROID_FIREBASE_BOM_VERSION` to override dependency versions for Firebase SDKs: 50 | 51 | $ cordova plugin add cordova-plugin-firebase-config \ 52 | --variable IOS_FIREBASE_POD_VERSION="9.3.0" \ 53 | --variable ANDROID_FIREBASE_BOM_VERSION="30.3.1" 54 | 55 | ### Adding required configuration files 56 | 57 | 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. 58 | 59 | 1. Put `google-services.json` and/or `GoogleService-Info.plist` into the root directory of your Cordova project 60 | 2. Add new tag for Android platform 61 | 62 | ```xml 63 | 64 | ... 65 | 66 | 67 | ... 68 | 69 | ... 70 | 71 | 72 | ``` 73 | 74 | ## Preferences 75 | 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. 76 | 77 | ```xml 78 | 79 | ... 80 | 81 | 82 | 83 | 84 | 85 | ... 86 | 87 | 88 | 89 | ``` 90 | 91 | On Android platform file `remote_config_defaults.xml` has a structure like below: 92 | ```xml 93 | 94 | 95 | 96 | param1 97 | value1 98 | 99 | 100 | param2 101 | value2 102 | 103 | 104 | ``` 105 | 106 | On iOS platform file `RemoteConfigDefaults.plist` has a structure like below: 107 | ```xml 108 | 109 | 110 | 111 | 112 | param1 113 | value1 114 | param2 115 | value2 116 | 117 | 118 | ``` 119 | 120 | 121 | 122 | ## Variables 123 | 124 | ### VALUE\_SOURCE\_DEFAULT 125 | 126 | **VALUE\_SOURCE\_DEFAULT**: `number` 127 | 128 | Indicates that the value returned was retrieved from the defaults set by the client. 129 | 130 | **`Constant`** 131 | 132 | ___ 133 | 134 | ### VALUE\_SOURCE\_REMOTE 135 | 136 | **VALUE\_SOURCE\_REMOTE**: `number` 137 | 138 | Indicates that the value returned was retrieved from the Firebase Remote Config Server. 139 | 140 | **`Constant`** 141 | 142 | ___ 143 | 144 | ### VALUE\_SOURCE\_STATIC 145 | 146 | **VALUE\_SOURCE\_STATIC**: `number` 147 | 148 | Indicates that the value returned is the static default value. 149 | 150 | **`Constant`** 151 | 152 | ## Functions 153 | 154 | ### activate 155 | 156 | **activate**(): `Promise`<`boolean`\> 157 | 158 | Asynchronously activates the most recently fetched configs, so that the fetched key value pairs take effect. 159 | 160 | **`Example`** 161 | 162 | ```ts 163 | cordova.plugins.firebase.config.activate(); 164 | ``` 165 | 166 | #### Returns 167 | 168 | `Promise`<`boolean`\> 169 | 170 | Fulfills promise with flag if current config was activated 171 | 172 | ___ 173 | 174 | ### fetch 175 | 176 | **fetch**(`expirationDuration`): `Promise`<`void`\> 177 | 178 | Starts fetching configs, adhering to the specified minimum fetch interval. 179 | 180 | **`Example`** 181 | 182 | ```ts 183 | cordova.plugins.firebase.config.fetch(8 * 3600); 184 | ``` 185 | 186 | #### Parameters 187 | 188 | | Name | Type | Description | 189 | | :------ | :------ | :------ | 190 | | `expirationDuration` | `number` | Minimum fetch interval in seconds | 191 | 192 | #### Returns 193 | 194 | `Promise`<`void`\> 195 | 196 | Callback when operation is completed 197 | 198 | ___ 199 | 200 | ### fetchAndActivate 201 | 202 | **fetchAndActivate**(): `Promise`<`boolean`\> 203 | 204 | Asynchronously fetches and then activates the fetched configs. 205 | 206 | **`Example`** 207 | 208 | ```ts 209 | cordova.plugins.firebase.config.fetchAndActivate(); 210 | ``` 211 | 212 | #### Returns 213 | 214 | `Promise`<`boolean`\> 215 | 216 | Fulfills promise with flag if current config was activated 217 | 218 | ___ 219 | 220 | ### getBoolean 221 | 222 | **getBoolean**(`key`): `Promise`<`boolean`\> 223 | 224 | Returns the boolean parameter value for the given key 225 | 226 | **`Example`** 227 | 228 | ```ts 229 | cordova.plugins.firebase.config.getBoolean("myBool").then(function(value) { 230 | // use value from remote config 231 | }); 232 | ``` 233 | 234 | #### Parameters 235 | 236 | | Name | Type | Description | 237 | | :------ | :------ | :------ | 238 | | `key` | `string` | Parameter key | 239 | 240 | #### Returns 241 | 242 | `Promise`<`boolean`\> 243 | 244 | Fulfills promise with parameter value 245 | 246 | ___ 247 | 248 | ### getBytes 249 | 250 | **getBytes**(`key`): `Promise`<`ArrayBuffer`\> 251 | 252 | Returns the bytes parameter value for the given key 253 | 254 | **`Example`** 255 | 256 | ```ts 257 | cordova.plugins.firebase.config.getBytes("myByteArray").then(function(value) { 258 | // use value from remote config 259 | }); 260 | ``` 261 | 262 | #### Parameters 263 | 264 | | Name | Type | Description | 265 | | :------ | :------ | :------ | 266 | | `key` | `string` | Parameter key | 267 | 268 | #### Returns 269 | 270 | `Promise`<`ArrayBuffer`\> 271 | 272 | Fulfills promise with parameter value 273 | 274 | ___ 275 | 276 | ### getNumber 277 | 278 | **getNumber**(`key`): `Promise`<`number`\> 279 | 280 | Returns the number parameter value for the given key 281 | 282 | **`Example`** 283 | 284 | ```ts 285 | cordova.plugins.firebase.config.getNumber("myNumber").then(function(value) { 286 | // use value from remote config 287 | }); 288 | ``` 289 | 290 | #### Parameters 291 | 292 | | Name | Type | Description | 293 | | :------ | :------ | :------ | 294 | | `key` | `string` | Parameter key | 295 | 296 | #### Returns 297 | 298 | `Promise`<`number`\> 299 | 300 | Fulfills promise with parameter value 301 | 302 | ___ 303 | 304 | ### getString 305 | 306 | **getString**(`key`): `Promise`<`string`\> 307 | 308 | Returns the string parameter value for the given key 309 | 310 | **`Example`** 311 | 312 | ```ts 313 | cordova.plugins.firebase.config.getString("myStr").then(function(value) { 314 | // use value from remote config 315 | }); 316 | ``` 317 | 318 | #### Parameters 319 | 320 | | Name | Type | Description | 321 | | :------ | :------ | :------ | 322 | | `key` | `string` | Parameter key | 323 | 324 | #### Returns 325 | 326 | `Promise`<`string`\> 327 | 328 | Fulfills promise with parameter value 329 | 330 | ___ 331 | 332 | ### getValueSource 333 | 334 | **getValueSource**(`key`): `Promise`<`number`\> 335 | 336 | Returns source of the value for the specified key. 337 | 338 | **`Example`** 339 | 340 | ```ts 341 | cordova.plugins.firebase.config.getValueSource("myArbitraryValue").then(function(source) { 342 | if (source === cordova.plugins.firebase.config.VALUE_SOURCE_DEFAULT) { 343 | // ... 344 | } 345 | }); 346 | ``` 347 | 348 | #### Parameters 349 | 350 | | Name | Type | Description | 351 | | :------ | :------ | :------ | 352 | | `key` | `string` | Parameter key | 353 | 354 | #### Returns 355 | 356 | `Promise`<`number`\> 357 | 358 | Fulfills promise with parameter value 359 | --------------------------------------------------------------------------------