Giter Site home page Giter Site logo

firebase-remote-config's Introduction

Capacitor Firebase Remote Config Plugin

Capacitory community plugin for firebase remote config.

Maintainers

Maintainer GitHub Social Sponsoring Company
Priyank Patel priyankpat @priyankpat_ Ionic

Mainteinance Status: Actively Maintained

Installation

To use npm

npm install @capacitor-community/firebase-remote-config

To use yarn

yarn add @capacitor-community/firebase-remote-config

Sync native files

npx cap sync

On iOS, no further steps are needed.

On Android, register the plugin in your main activity:

import com.getcapacitor.community.firebaserc.FirebaseRemoteConfig;

public class MainActivity extends BridgeActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(
        savedInstanceState,
        new ArrayList<Class<? extends Plugin>>() {

          {
            // Additional plugins you've installed go here
            // Ex: add(TotallyAwesomePlugin.class);
            add(FirebaseRemoteConfig.class);
          }
        }
      );
  }
}

Configuration

Download appropriate google-services.json or GoogleService-Info.plist and place it in the correct platform app directory.

For Android: /android/app

For iOS: /ios/App/App

Examples

Click here for example on how to implement this plugin

You can also clone the repository

git clone https://github.com/priyankpat/capacitor-plugins-example
git checkout -b firebase-remote-config

Supported methods

Name Android iOS Web
initializeFirebase
setDefaultWebConfig
initialize
fetch
activate
fetchAndActivate
getBoolean
getByteArray
getNumber
getString

Usage

// Must import the package once to make sure the web support initializes
import "@capacitor-community/firebase-remote-config";

import { Plugins } from "@capacitor/core";

const { FirebaseRemoteConfig } = Plugins;

/**
 * NOTE: Web Platform only!
 * This method will initialize firebase app if not yet initialized.
 * @param firebase configs - from google-service.json or GoogleService-Info.plist
 * @returns void
 */
FirebaseRemoteConfig.initializeFirebase({
  apiKey: "...",
  authDomain: "...",
  databaseURL: "...",
  projectId: "...",
  storageBucket: "...",
  messagingSenderId: "...",
  appId: "...",
  measurementId: "...",
});

/**
 * NOTE: Web Platform only!
 * This method will set default remote config values.
 * @param options - key/value params with default values
 * @returns void
 */
FirebaseRemoteConfig.setDefaultWebConfig({
  has_sale: false,
  event_name: "clearance_event",
});

/**
 * This method will configure remote config object instance and set the minimum fetch interval to allow for frequest refreshes.
 * @param minimumFetchIntervalInSeconds - interval in seconds (default: 3600)
 * @returns void
 */
FirebaseRemoteConfig.initialize({
  minimumFetchIntervalInSeconds: 3600,
});

/**
 * This method will execute fetch task to retrieve config
 * @param none
 * @returns void
 */
FirebaseRemoteConfig.fetch();

/**
 * This method will activate the fetched values making it available for your app
 * @param none
 * @returns void
 */
FirebaseRemoteConfig.activate();

/**
 * This method will fetch and activate the values making it available for your app
 * @param none
 * @returns void
 */
FirebaseRemoteConfig.fetchAndActivate();

/**
 * This method will return the parameter value for a given key in boolean
 * @param key - key to obtain boolean value
 * @returns key - key used to obtain value
 *          value - boolean value for a given key
 *          source - Indicates that the source of value retrieved (default, remote, static)
 */
FirebaseRemoteConfig.getBoolean({
  key: "bool key",
});

/**
 * This method will return the parameter value for a given key in byte array
 * @param key - key to obtain byte array value
 * @returns key - key used to obtain value
 *          value - byte array value for a given key
 *          source - Indicates that the source of value retrieved (default, remote, static)
 */
FirebaseRemoteConfig.getByteArray({
  key: "array key",
});

/**
 * This method will return the parameter value for a given key in double
 * @param key - key to obtain double value
 * @returns key - key used to obtain value
 *          value - double value for a given key
 *          source - Indicates that the source of value retrieved (default, remote, static)
 */
FirebaseRemoteConfig.getNumber({
  key: "number key",
});

/**
 * This method will return the parameter value for a given key in string
 * @param key - key to obtain string value
 * @returns key - key used to obtain value
 *          value - string value for a given key
 *          source - Indicates that the source of value retrieved (default, remote, static)
 */
FirebaseRemoteConfig.getString({
  key: "string key",
});

firebase-remote-config's People

Contributors

maurotn avatar mlynch avatar priyankpat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

firebase-remote-config's Issues

Update or confirm project maintenance status

Thanks for publishing this project! The README states

Mainteinance Status: Actively Maintained

but the activity seems to have stagnated and there are a few sensible PRs hanging.

There is absolutely no shame in admitting that time or energy is lacking. If @priyankpat is blocked, I would suggest updating the README to say Maintenance status: seeking maintainers. If @priyankpat is available as maintainer, it think it would be a great comfort to potential users of this project to have that confirmed.

(We are implementing Remote Config in our Capacitor-based app and would be willing to contribute. Maybe @mic345 is interested as well, considering the extensive PR submitted. Any way forward here is good. 🙂)

Several crashes on Android reported by Crashlytics

Describe the bug
I'm getting many crashes reported by Firebase Crashlytics caused by some messaging dependency (com.google.firebase.iid.zzbe and com.getcapacitor.CapacitorFirebaseMessagingService) .

To Reproduce
I was not able to reproduce it consistently. The error happened more frequent in production.

Expected behavior
While I can handle some crashes here and there due to huge ecosystem Android has, I've had a very small number Crash-Free users on Android, 64%.

Screenshots
Link to gallery
SS 1
SS 2
SS 3
SS 4

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):
Android devices. No pattern has been found in terms of OS Versions

Additional context
I'm also using some other capacitor-community plugins that may have some impact (@capacitor-community/admob, @capacitor-community/firebase-analytics, @capacitor-community/firebase-crashlytics, @capacitor-community/firebase-remote-config, @capacitor-community/media). I'll attach the complete plugin list below:

ionic info
Ionic:

   Ionic CLI                     : 6.12.0 
   Ionic Framework               : @ionic/angular 5.3.4
   @angular-devkit/build-angular : 0.901.12
   @angular-devkit/schematics    : 9.1.12
   @angular/cli                  : 9.1.12
   @ionic/angular-toolkit        : 2.3.3

Capacitor:

   Capacitor CLI   : 2.4.2
   @capacitor/core : 2.4.2

Utility:

   cordova-res                          : not installed
   native-run (update available: 1.2.1) : 1.0.0

System:

   NodeJS : v14.6.0
   npm    : 6.14.8
   OS     : macOS Catalina

package.json

"dependencies": {
    "@angular/common": "^9.1.12",
    "@angular/core": "^9.1.12",
    "@angular/forms": "^9.1.12",
    "@angular/platform-browser": "^9.1.12",
    "@angular/platform-browser-dynamic": "^9.1.12",
    "@angular/router": "^9.1.12",
    "@capacitor-community/admob": "^1.2.0-0",
    "@capacitor-community/firebase-analytics": "^0.2.0",
    "@capacitor-community/firebase-crashlytics": "^0.3.0",
    "@capacitor-community/firebase-remote-config": "^0.1.3",
    "@capacitor-community/media": "^1.0.1",
    "@capacitor/android": "^2.4.0",
    "@capacitor/core": "^2.4.0",
    "@capacitor/ios": "^2.4.0",
    "@ionic-native/core": "^5.28.0",
    "@ionic-super-tabs/angular": "^7.0.8",
    "@ionic/angular": "^5.3.2",
    "@ionic/storage": "^2.3.0",
    "@ngx-translate/core": "^12.1.2",
    "@ngx-translate/http-loader": "^4.0.0",
    "cordova-sqlite-storage": "^5.0.1",
    "ngx-countup": "^7.3.3",
    "rxjs": "~6.5.1",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.901.12",
    "@angular/cli": "^9.1.12",
    "@angular/compiler": "^9.1.12",
    "@angular/compiler-cli": "^9.1.12",
    "@angular/language-service": "^9.1.12",
    "@capacitor/cli": "^2.4.0",
    "@ionic/angular-toolkit": "^2.3.3",
    "@types/jasmine": "^3.5.14",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.12.54",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^5.2.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "ts-node": "~8.3.0",
    "tslint": "^6.1.3",
    "typescript": "~3.8.3"
  }

FirebaseRemoteConfig.initializeFirebase is not a function

I'm using ionic capacitor for my ionic application.
When i run application i got the following errors every time


Code :

FirebaseRemoteConfig.initializeFirebase(environment.firebase)
FirebaseRemoteConfig.initialize({
minimumFetchIntervalInSeconds: 3600,
})

------
Screenshot 2020-11-19 at 2 35 49 PM

[Error] ERROR
Error: Uncaught (in promise): TypeError: FirebaseRemoteConfig.initializeFirebase is not a function. (In 'FirebaseRemoteConfig.initializeFirebase(src_environments_environment__WEBPACK_IMPORTED_MODULE_4__["environment"].firebase)', 'FirebaseRemoteConfig.initializeFirebase' is undefined) capacitor://localhost/main-es2015.js:2581:52 generatorResume@[native code] capacitor://localhost/vendor-es2015.js:175643:75 ZoneAwarePromise@capacitor://localhost/polyfills-es2015.js:4066:41 __awaiter@capacitor://localhost/vendor-es2015.js:175639:36 onInvoke@capacitor://localhost/vendor-es2015.js:90359:39 run@capacitor://localhost/polyfills-es2015.js:3229:53 capacitor://localhost/polyfills-es2015.js:3963:43 onInvokeTask@capacitor://localhost/vendor-es2015.js:90337:43 runTask@capacitor://localhost/polyfills-es2015.js:3273:61 drainMicroTaskQueue@capacitor://localhost/polyfills-es2015.js:3675:46 invokeTask@capacitor://localhost/polyfills-es2015.js:3590:44 timer@capacitor://localhost/polyfills-es2015.js:5658:38
resolvePromise — zone-evergreen.js:798
resolvePromise — zone-evergreen.js:750
(anonymous function) — zone-evergreen.js:860
onInvokeTask — core.js:41632
runTask — zone-evergreen.js:167
drainMicroTaskQueue — zone-evergreen.js:569
invokeTask — zone-evergreen.js:484
timer — zone-evergreen.js:2552
capacitorConsole (user-script:2:78)
defaultErrorLogger (vendor-es2015.js:58657)
handleError (vendor-es2015.js:58710)
next (vendor-es2015.js:91191)
(anonymous function) (vendor-es2015.js:86553)
__tryOrUnsub (vendor-es2015.js:165665)
next (vendor-es2015.js:165604)
_next (vendor-es2015.js:165554)
next (vendor-es2015.js:165531)
next (vendor-es2015.js:165317)
emit (vendor-es2015.js:86513)
run (polyfills-es2015.js:3229)
onHandleError (vendor-es2015.js:90396)
runGuarded (polyfills-es2015.js:3242)
(anonymous function) (polyfills-es2015.js:3776)
drainMicroTaskQueue (polyfills-es2015.js:3682)
invokeTask (polyfills-es2015.js:3590)
timer (polyfills-es2015.js:5658)

[Error] ERROR
Error: Uncaught (in promise): TypeError: FirebaseRemoteConfig. fetchAndActivate is not a function. (In 'FirebaseRemoteConfig. fetchAndActivate(src_environments_environment__WEBPACK_IMPORTED_MODULE_4__["environment"].firebase)', 'FirebaseRemoteConfig. fetchAndActivate' is undefined) capacitor://localhost/main-es2015.js:2581:52 generatorResume@[native code] capacitor://localhost/vendor-es2015.js:175643:75 ZoneAwarePromise@capacitor://localhost/polyfills-es2015.js:4066:41 __awaiter@capacitor://localhost/vendor-es2015.js:175639:36 onInvoke@capacitor://localhost/vendor-es2015.js:90359:39 run@capacitor://localhost/polyfills-es2015.js:3229:53 capacitor://localhost/polyfills-es2015.js:3963:43 onInvokeTask@capacitor://localhost/vendor-es2015.js:90337:43 runTask@capacitor://localhost/polyfills-es2015.js:3273:61 drainMicroTaskQueue@capacitor://localhost/polyfills-es2015.js:3675:46 invokeTask@capacitor://localhost/polyfills-es2015.js:3590:44 timer@capacitor://localhost/polyfills-es2015.js:5658:38
resolvePromise — zone-evergreen.js:798
resolvePromise — zone-evergreen.js:750
(anonymous function) — zone-evergreen.js:860
onInvokeTask — core.js:41632
runTask — zone-evergreen.js:167
drainMicroTaskQueue — zone-evergreen.js:569
invokeTask — zone-evergreen.js:484
timer — zone-evergreen.js:2552
capacitorConsole (user-script:2:78)
defaultErrorLogger (vendor-es2015.js:58657)
handleError (vendor-es2015.js:58710)
next (vendor-es2015.js:91191)
(anonymous function) (vendor-es2015.js:86553)
__tryOrUnsub (vendor-es2015.js:165665)
next (vendor-es2015.js:165604)
_next (vendor-es2015.js:165554)
next (vendor-es2015.js:165531)
next (vendor-es2015.js:165317)
emit (vendor-es2015.js:86513)
run (polyfills-es2015.js:3229)
onHandleError (vendor-es2015.js:90396)
runGuarded (polyfills-es2015.js:3242)
(anonymous function) (polyfills-es2015.js:3776)
drainMicroTaskQueue (polyfills-es2015.js:3682)
invokeTask (polyfills-es2015.js:3590)
timer (polyfills-es2015.js:5658)

Add web support

Is your feature request related to a problem? Please describe.
Firebase Remote Config not supported by web at the moment.

Describe the solution you'd like
Implement Web Remote Config

Describe alternatives you've considered
N/A

Additional context
N/A

iOS first fetchAndActivate call return empty value

Describe the bug
On iOS the first fetchAndActivate method followed by getString return an empty value.
{"value":"","source":2,"key":"config"}
On the others attempts it return the value with different source.
{"key":"config","value":"...","source":0}

To Reproduce
I have try to use this plugin with iOS and Android and replicate the example in an Ionic with Angular project.
Inside the platform.ready()
FirebaseRemoteConfig.initialize({ minimumFetchIntervalInSeconds: 3600 }); FirebaseRemoteConfig.fetchAndActivate().then(() => { FirebaseRemoteConfig.getString({key: 'config' }) .then((rc) => { console.log(JSON.stringify(rc)); }); });

Expected behavior
Give the value since the first attempt on iOS.
On Android it works fine.

Smartphone (please complete the following information):

  • Device: iPad
  • OS: 13.5.1

Additional context
In this project I'm using the other two firebase plugin available on capacitor-community:

  • firebase-analytics: patched with this patch
  • fcm: fixed upgrading the version of firebaseMessaging in variables.gradle file: firebaseMessagingVersion = '20.1.6'

Error: x.activate is not a function on iOS

Describe the bug

Calling FirebaseRemoteConfig.activate() throws Error: x.activate is not a function on iOS.

To Reproduce

  1. Start an iOS project
  2. Call FirebaseRemoteConfig.activate()
  3. Bug: Error: x.activate is not a function on iOS is thrown.

Expected behavior

Method to be working.

minimumFetchIntervalInSeconds argument in the initialize() method is not working for Android

Describe the bug
When I set the minimumFetchIntervalInSeconds value on the initialize method, it's not working for Android(The value is not setted so can't fetch de new values from Firebase Remote Config platform).

Example:

FirebaseRemoteConfig.initialize({
minimumFetchIntervalInSeconds: 0,
})

To Reproduce
Steps to reproduce the behavior:

  1. Try setting different values in minimumFetchIntervalInSeconds and compile for Android. You will see that these values are not setted. I mean, the Firebase Remote Config Console values are not setted in the app.

Expected behavior
I expect to get the new Firebase Remote Config Console values but they are not getted.

Smartphone (please complete the following information):

  • Device: Motorola Moto G9 Play
  • OS: Android 10

Possible Solution
I was debugging the app, and saw that in the FirebaseRemoteConfig.java file, line 58(Method initialize), there is the next line:
.setFetchTimeoutInSeconds(minFetchTimeInSecs)
I replaced that line for this, and the plugin worked perfectly:
.setMinimumFetchIntervalInSeconds(minFetchTimeInSecs)

It's setting the TimeOut value with the minFetchTimeInSect instead of setting the MinimumFetchIntervalInSeconds value.

Hope you can understand what I tried to explain. Please, let me know if you need me to explain anything else.

Best regards, Hernán!

Firebase App has not yet initialized.

Describe the bug
Error message received:
`Firebase App has not yet initialized.

(anonymous) @ instrument.js:108
  (anonymous) @
  fulfilled @
  invoke @
  run @
  (anonymous) @
  invokeTask @
  runTask @
  drainMicroTaskQueue @
  invokeTask @
  invokeTask @
  globalZoneAwareCallback @
  load (async)  
  customScheduleGlobal @
  scheduleTask @
  scheduleTask @
  scheduleEventTask @
  (anonymous) @
  (anonymous) @
  (anonymous) @
  desc.set @
  (anonymous) @
  (anonymous) @
  ZoneAwarePromise @
  loadScripts @
  (anonymous) @
  (anonymous) @
  ZoneAwarePromise @
  push../node_modules/@capacitor-community/firebase-remote-config/dist/esm/web.js.__awaiter @
  configure @
  FirebaseRemoteConfigWeb @
  ./node_modules/@capacitor-community/firebase-remote-config/dist/esm/web.js @
  webpack_require @
  ./node_modules/@capacitor-community/firebase-remote-config/dist/esm/index.js @
  webpack_require @
  ./src/app/services/general/config.service.ts @
  webpack_require @
  ./src/app/services/event/event-list.service.ts @
  webpack_require @
  ./src/app/services/user/user.service.ts @
  webpack_require @
  ./src/app/app.component.ts @
  webpack_require @
  ./src/app/app.module.ts @
  webpack_require @
  ./src/main.ts @
  webpack_require @
  0 @
  webpack_require @
  checkDeferredModules @
  webpackJsonpCallback @
  (anonymous)

`

To Reproduce
Will see this error as long as I import the plugin.
import '@capacitor-community/firebase-remote-config'; import { Plugins } from '@capacitor/core'; const { FirebaseRemoteConfig } = Plugins;

Additional context
"@capacitor-community/firebase-remote-config": "^0.1.3",

Ionic:

Ionic CLI : 6.11.0
Ionic Framework : @ionic/angular 5.2.2
@angular-devkit/build-angular : 0.901.9
@angular-devkit/schematics : 9.1.9
@angular/cli : 9.1.9
@ionic/angular-toolkit : 2.2.0

Capacitor:

Capacitor CLI : 2.2.0
@capacitor/core : 2.4.0

Utility:

cordova-res : 0.15.1
native-run : 1.0.0

System:

NodeJS : v12.16.1
npm : 6.14.7
OS : macOS Catalina

Getter methods on web plugin return wrong types

Describe the bug

Web version getter methods return different type (e.g. Promise<string|int|boolean>) than native versions (e.g. Promise<RCReturnData>).

To Reproduce

  1. Call FirebaseRemoteConfig.getString on web version => returns Promise<string>
  2. Call FirebaseRemoteConfig.getString on iOS version => returns Promise<RCReturnData>

Expected behavior

Return the same type regardless the platform.

Using both firebase-remote-config and firebase-analytics on the same project throws Error: Uncaught (in promise): Firebase app already exists

Describe the bug

Using both firebase-remote-config and firebase-analytics on the same project throws core.js:4197 ERROR Error: Uncaught (in promise): Firebase app already exists.

This happens due to both modules require the call to their initializeFirebase respectively and both functions rejects if window.firebase is already initialized. Note that if you do not call those functions, the services are not operational due to the firebase service member not being set (this.analyticsRef and this.remoteConfigRef).

To Reproduce

  1. Create a vanilla project.
  2. Add both @capacitor-community/firebase-analytics and @capacitor-community/firebase-remote-config.
  3. Add an ionic service for each of the services.
  4. On each of the services call initializeFirebase

Expected behavior

Support using both @capacitor-community/firebase-analytics and @capacitor-community/firebase-remote-config on the same project.

Additional context

Ionic:

Ionic CLI : 6.11.8 (/home/vagrant/.config/yarn/global/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.4.2
@angular-devkit/build-angular : 0.1000.8
@angular-devkit/schematics : 10.0.8
@angular/cli : 10.0.8
@ionic/angular-toolkit : 2.3.3

Capacitor:

Capacitor CLI : 2.4.2
@capacitor/core : 2.4.2

Utility:

cordova-res : not installed
native-run (update available: 1.2.2) : 1.2.1

System:

NodeJS : v12.18.3 (/home/vagrant/.nvm/versions/node/v12.18.3/bin/node)
npm : 6.14.6
OS : Linux 4.9

Breaks when updating to Firebase/RemoteConfig 7.0.0

Describe the bug
When building the app for iOS I get the following error:
node_modules/@capacitor-community/firebase-remote-config/ios/Plugin/Plugin.swift:53:56: extra argument 'completionHandler' in call
It happened after updating to Firebase/RemoteConfig 7.0.0

To Reproduce
Update to latest version of Firebase/RemoteConfig:

pod repo update
pod install

Then build app in xcode

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.