Firebaseβ

Improve this doc

This plugin is still in beta stage and may not work as expected. Please submit any issues to the plugin repo.

This plugin brings push notifications, analytics, event tracking, crash reporting and more from Google Firebase to your Cordova project! Android and iOS supported (including iOS 10).

Repo: https://github.com/arnesson/cordova-plugin-firebase

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-firebase
    $ npm install --save @ionic-native/firebase
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { Firebase } from '@ionic-native/firebase';

constructor(private firebase: Firebase) { }

...

this.firebase.getToken()
  .then(token => console.log(`The token is ${token}`)) // save the token server-side and use it to push notifications to this device
  .catch(error => console.error('Error getting token', error));

this.firebase.onTokenRefresh()
  .subscribe((token: string) => console.log(`Got a new token ${token}`));

Instance Members

getToken()

Get the device token

Returns: Promise<any>

onTokenRefresh()

Get notified when a token is refreshed

Returns: Observable<any>

onNotificationOpen()

Get notified when the user opens a notification

Returns: Observable<any>

grantPermission()

Platforms:iOS 

Grant permission to receive push notifications

Returns: Promise<any>

hasPermission()

Check permission to receive push notifications

Returns: Promise<{isEnabled: boolean}>

setBadgeNumber(badgeNumber)

Set icon badge number. Set to 0 to clear the badge.

Param Type Details
badgeNumber number

Returns: Promise<any>

getBadgeNumber()

Get icon badge number

Returns: Promise<any>

subscribe(topic)

Subscribe to a topic

Param Type Details
topic string

Returns: Promise<any>

unsubscribe(topic)

Unsubscribe from a topic

Param Type Details
topic string

Returns: Promise<any>

unregister()

Unregister from firebase, used to stop receiving push notifications. Call this when you logout user from your app.

logEvent(type, data)

Log an event using Analytics

Param Type Details
type string
data Object

Returns: Promise<any>

logError(message)

Log an Error using FirebaseCrash

Param Type Details
message string

Returns: Promise<any>

setScreenName(name)

Set the name of the current screen in Analytics

Param Type Details
name string

Screen name

Returns: Promise<any>

setUserId(userId)

Set a user id for use in Analytics

Param Type Details
userId string

Returns: Promise<any>

setUserProperty(name, value)

Set a user property for use in Analytics

Param Type Details
name string
value string

Returns: Promise<any>

fetch(cacheExpirationSeconds)

Fetch Remote Config parameter values for your app

Param Type Details
cacheExpirationSeconds number

Returns: Promise<any>

activateFetched()

Activate the Remote Config fetched config

Returns: Promise<any>

getValue(key, namespace)

Retrieve a Remote Config value

Param Type Details
key string
namespace string

Optional

Returns: Promise<any>

getByteArray(key, namespace)

Platforms:Android 

Retrieve a Remote Config byte array

Param Type Details
key string
namespace string

Optional

Returns: Promise<any>

getInfo()

Platforms:Android 

Get the current state of the FirebaseRemoteConfig singleton object

Returns: Promise<any>

setConfigSettings(settings)

Platforms:Android 

Change the settings for the FirebaseRemoteConfig object’s operations

Param Type Details
settings Object

Returns: Promise<any>

setDefaults(defaults, namespace)

Platforms:Android 

Set defaults in the Remote Config

Param Type Details
defaults Object
namespace string

Optional

Returns: Promise<any>

getVerificationID(phoneNumber)

Platforms:iOS 

Sends an SMS to the user with the SMS verification code and returns the Verification ID required to sign in using phone authentication

Param Type Details
phoneNumber string

Returns: Promise<any>

verifyPhoneNumber(phoneNumber, timeoutDuration)

Platforms:Android 

Sends an SMS to the user with the SMS verification code and returns the Verification ID required to sign in using phone authentication

Param Type Details
phoneNumber string

the phone number, including '+' and country code

timeoutDuration number

the timeout in sec - no more SMS will be sent to this number until this timeout expires

Returns: Promise<any>

setAnalyticsCollectionEnabled(enabled)

Allows the user to enable/disable analytics collection

Param Type Details
enabled booleab

value to set collection

Returns: Promise<any>

API

Native

General