npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

capacitor-firebase-push

v1.2.7

Published

Capacitor Plugin for Firebase Push

Downloads

70

Readme

Capacitor Firebase Push

Maintenance npm

👉🏼 Note: this Plugin is developed for Capacitor V3

This Plugin it used for Firebase Push Messages. It does support Data (silent) notifications!

Donate

This and other Open-Source Cordova Plugins are developed in my free time. To help ensure this plugin is kept updated, new features are added and bugfixes are implemented quickly, please donate a couple of dollars (or a little more if you can stretch) as this will help me to afford to dedicate time to its maintenance. Please consider donating if you're using this plugin in an app that makes you money, if you're being paid to make the app, if you're asking for new features or priority bug fixes.

Table of Content

Install

npm install capacitor-firebase-push
npx cap sync

Shutout

❤️

This Plugin was created to match every requirement I had for my app. These Plugins helped my a lot to create this one:

Setup

Android

Just follow the Android Setup Guide here

Variables

This plugin will use the following project variables (defined in your app's variables.gradle file):

  • $firebaseMessagingVersion version of com.google.firebase:firebase-messaging (default: `21.1.0)

Push Notifications icon

On Android, the Push Notifications icon with the appropriate name should be added to the AndroidManifest.xml file:

<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/push_icon_name" />

If no icon is specified Android will use the application icon, but push icon should be white pixels on a transparent backdrop. As the application icon is not usually like that, it will show a white square or circle. So it's recommended to provide the separate icon for Push Notifications.

Android Studio has an icon generator you can use to create your Push Notifications icon.

iOS

Start setting up your iOS Project like described here: https://capacitorjs.com/docs/v3/guides/push-notifications-firebase#integrating-firebase-with-our-native-ios-app

Stop before the Add the Firebase SDK via CocoaPods Part - we don't need that one.

After you updated the project (npx cap update ios), you have to add the following Initialization Code to your AppDelegate.swift:

  1. Add the Firebase Import:

    import Firebase
  2. Add the following two functions:

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
         Messaging.messaging().apnsToken = deviceToken
         Messaging.messaging().token(completion: { (token, error) in
             if let error = error {
                 NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
             } else if let token = token {
                 NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token)
             }
         })
     }
    
     func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
         NotificationCenter.default.post(name: Notification.Name.init("didReceiveRemoteNotification"), object: completionHandler, userInfo: userInfo)
     }

Config

Push notification appearance in foreground

On iOS you can configure the way the push notifications are displayed when the app is in foreground by providing the `presentationOptions in your capacitor.config.ts as an Array of Strings you can combine.

Possible values are:

  • badge: badge count on the app icon is updated (default value)
  • sound: the device will ring/vibrate when the push notification is received
  • alert: the push notification is displayed in a native dialog

An empty Array can be provided if none of the previous options are desired. pushNotificationReceived event will still be fired with the push notification information.

plugins: {
  FirebasePush: {
    presentationOptions: ["badge", "sound", "alert"]
  }
}

These fields can be overwritten if you pass create_notification: true in the data Part of the notification.

API

checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Check permission to receive push notifications.

Will always return "granted" on Android

Returns: Promise<PermissionStatus>

Since: 1.0.0


requestPermissions()

requestPermissions() => Promise<PermissionStatus>

Request permission to receive push notifications.

Will always return "granted" on Android

Returns: Promise<PermissionStatus>

Since: 1.0.0


register()

register() => Promise<void>

Register the app to receive push notifications.

Since: 1.0.0


unregister()

unregister() => Promise<void>

Should be called to unregister the Firebase Instance. For example if a User logs out.

Since: 1.1.0


getBadgeNumber()

getBadgeNumber() => Promise<BadgeCount>

Get icon badge Value

Only available on iOS

Returns: Promise<BadgeCount>

Since: 1.2.0


setBadgeNumber(...)

setBadgeNumber(options: BadgeCount) => Promise<void>

Set icon badge Value

Only available on iOS

| Param | Type | | ------------- | ------------------------------------------------- | | options | BadgeCount |

Since: 1.2.0


getDeliveredNotifications()

getDeliveredNotifications() => Promise<NotificationsResult>

Get notifications in Notification Center

Returns: Promise<NotificationsResult>

Since: 1.2.0


removeDeliveredNotifications(...)

removeDeliveredNotifications(options: NotificationsIds) => Promise<void>

Remove notifications from the notifications screen based on the id

| Param | Type | | ------------- | ------------------------------------------------------------- | | options | NotificationsIds |

Since: 1.2.0


removeAllDeliveredNotifications()

removeAllDeliveredNotifications() => Promise<void>

Remove all notifications from the notifications screen

Since: 1.2.0


addListener('token', ...)

addListener(eventName: 'token', listenerFunc: (result: TokenResult) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Called when a new fcm token is created

| Param | Type | | ------------------ | ------------------------------------------------------------------------ | | eventName | 'token' | | listenerFunc | (result: TokenResult) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 1.0.0


addListener('message', ...)

addListener(eventName: 'message', listenerFunc: (message: any) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Called when a new message is received

| Param | Type | | ------------------ | -------------------------------------- | | eventName | 'message' | | listenerFunc | (message: any) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 1.0.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all native listeners for this plugin.

Since: 1.0.0


Interfaces

PermissionStatus

| Prop | Type | Since | | ------------- | ----------------------------------------------------------- | ----- | | receive | PermissionState | 1.0.0 |

BadgeCount

| Prop | Type | Since | | ----------- | ------------------- | ----- | | count | number | 1.2.0 |

NotificationsResult

| Prop | Type | Since | | ------------------- | ------------------ | ----- | | notifications | any[] | 1.2.0 |

NotificationsIds

| Prop | Type | Since | | --------- | --------------------- | ----- | | ids | string[] | 1.2.0 |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

TokenResult

| Prop | Type | | ----------- | ------------------- | | token | string |

Type Aliases

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

Changelog

The full Changelog is available here