Socket
Socket
Sign inDemoInstall

cordova-plugin-firebase

Package Overview
Dependencies
0
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cordova-plugin-firebase

Cordova plugin for Google Firebase


Version published
Weekly downloads
335
increased by3.4%
Maintainers
1
Install size
28.5 MB
Created
Weekly downloads
 

Readme

Source

cordova-plugin-firebase

Cordova plugin for Google Firebase

Installation

See npm package for versions - https://www.npmjs.com/package/cordova-plugin-firebase

Install the plugin by adding it your project's config.xml:

<plugin name="cordova-plugin-firebase" spec="0.1.10" />

or by running:

cordova plugin add cordova-plugin-firebase@0.1.10 --save

Download your Firebase configuration files, GoogleService-Info.plist for ios and google-services.json for android, and place them in the root folder of your cordova project:

- My Project/
    platforms/
    plugins/
    www/
    config.xml
    google-services.json       <--
    GoogleService-Info.plist   <--
    ...

See https://support.google.com/firebase/answer/7015592 for details how to download the files from firebase.

This plugin uses a hook (after prepare) that copies the configuration files to the right place, namely platforms/ios/<My Project>/Resources for ios and platforms/android for android.

Note that the Firebase SDK requires the configuration files to be present and valid, otherwise your app will crash on boot or Firebase features won't work.

Notes about PhoneGap Build

Hooks does not work with PhoneGap Build. This means you will have to manually make sure the configuration files are included. One way to do that is to make a private fork of this plugin and replace the placeholder config files (see src/ios and src/android) with your actual ones.

Methods

getInstanceId

Get the device id (token):

window.FirebasePlugin.getInstanceId(function(token) {
    // save this server-side and use it to push notifications to this device
    console.log(token);
}, function(error) {
    console.error(error);
});

Note that token will be null if it has not been established yet

onNotificationOpen

Register notification callback:

window.FirebasePlugin.onNotificationOpen(function(notification) {
    console.error(notification);
}, function(error) {
    console.error(error);
});

Notification flow:

  1. App is in foreground:
    1. User receives the notification data in the JavaScript callback without any notification on the device itself (this is the normal behaviour of push notifications, it is up to you, the developer, to notify the user)
  2. App is in background:
    1. User receives the notification message in its device notification bar
    2. User taps the notification and the app opens
    3. User receives the notification data in the JavaScript callback

grantPermission (iOS only)

Grant permission to recieve push notifications (will trigger prompt):

window.FirebasePlugin.grantPermission();

setBadgeNumber

Set a number on the icon badge:

window.FirebasePlugin.setBadgeNumber(3);

Set 0 to clear the badge

window.FirebasePlugin.setBadgeNumber(0);

getBadgeNumber

Get icon badge number:

window.FirebasePlugin.getBadgeNumber(function(n) {
    console.log(n);
});

subscribe

Subscribe to a topic:

window.FirebasePlugin.subscribe("example");

unsubscribe

Unsubscribe from a topic:

window.FirebasePlugin.unsubscribe("example");

logEvent

Log an event using Analytics:

window.FirebasePlugin.logEvent("page_view", {page: "dashboard"});

setUserId

Set a user id for use in Analytics:

window.FirebasePlugin.setUserId("user_id");

setUserProperty

Set a user property for use in Analytics:

window.FirebasePlugin.setUserProperty("name", "value");

fetch (Android only)

Fetch Remote Config parameter values for your app:

window.FirebasePlugin.fetch();
// or, specify the cacheExpirationSeconds
window.FirebasePlugin.fetch(600);

activateFetched (Android only)

Activate the Remote Config fetched config:

window.FirebasePlugin.activateFetched(function(activated) {
    // activated will be true if there was a fetched config activated,
    // or false if no fetched config was found, or the fetched config was already activated.
    console.log(activated);
}, function(error) {
    console.error(error);
});

getValue (Android only)

Retrieve a Remote Config value:

window.FirebasePlugin.getValue("key", function(value) {
    console.log(value);
}, function(error) {
    console.error(error);
});
// or, specify a namespace for the config value
window.FirebasePlugin.getValue("key", "namespace", function(value) {
    console.log(value);
}, function(error) {
    console.error(error);
});

getByteArray (Android only)

Retrieve a Remote Config byte array:

window.FirebasePlugin.getByteArray("key", function(bytes) {
    // a Base64 encoded string that represents the value for "key"
    console.log(bytes.base64);
    // a numeric array containing the values of the byte array (i.e. [0xFF, 0x00])
    bytes.array;
}, function(error) {
    console.error(error);
});
// or, specify a namespace for the byte array
window.FirebasePlugin.getByteArray("key", "namespace", function(bytes) {
    // a Base64 encoded string that represents the value for "key"
    console.log(bytes.base64);
    // a numeric array containing the values of the byte array (i.e. [0xFF, 0x00])
    bytes.array;
}, function(error) {
    console.error(error);
});

getInfo (Android only)

Get the current state of the FirebaseRemoteConfig singleton object:

window.FirebasePlugin.getInfo(function(info) {
    // the status of the developer mode setting (true/false)
    console.log(info.configSettings.developerModeEnabled);
    // the timestamp (milliseconds since epoch) of the last successful fetch
    console.log(info.fetchTimeMillis);
    // the status of the most recent fetch attempt (int)
    console.log(info.lastFetchStatus);
}, function(error) {
    console.error(error);
});

setConfigSettings (Android only)

Change the settings for the FirebaseRemoteConfig object's operations:

var settings = {
    developerModeEnabled: true
}
window.FirebasePlugin.setConfigSettings(settings);

setDefaults (Android only)

Set defaults in the Remote Config:

// define defaults
var defaults = {
    // map property name to value in Remote Config defaults
    mLong: 1000,
    mString: 'hello world',
    mDouble: 3.14,
    mBoolean: true,
    // map "mBase64" to a Remote Config byte array represented by a Base64 string
    // Note: the Base64 string is in an array in order to differentiate from a string config value
    mBase64: ["SGVsbG8gV29ybGQ="],
    // map "mBytes" to a Remote Config byte array represented by a numeric array
    mBytes: [0xFF, 0x00]
}
// set defaults
window.FirebasePlugin.setDefaults(defaults);
// or, specify a namespace
window.FirebasePlugin.setDefaults(defaults, "namespace");

Keywords

FAQs

Last updated on 10 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc