Push Notifications Implementation #1607
bryce-mcmath
started this conversation in
Guides
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Push Notifications in BC Wallet
Intro
We've been implementing Firebase push notifications in BC Wallet, and I thought I should put this guide and list of notables together for other Bifold teams looking to implement their own Firebase push notifications and for other BC Wallet devs to get up to speed quickly without missing any key details.
Overview
There are several components to get push notifications working end-to-end: setting up a Firebase project for your iOS and Android apps, adding relevant keys, a dependency and module addition in Bifold, Firebase installation and setup in
bc-wallet-mobile
, mediator logic and Firebase implementation inbc-wallet-mobile
, and an addition to thearies-mediator-service
to include an FCM plugin. You'll also have to add relevant environment variables tobc-wallet-mobile
andaries-mediator-service
.Setting Up Firebase Project
To setup a Firebase project for your application as we did for BC Wallet, follow along with the below video:
Firebase Project Initial Setup
You will need to add a iOS plist file and equivalent Android JSON file to your app project, as seen in the above video. These contain an API key but it's ok to check into source control as explained by the Firebase team here.
In addition to the above steps you will need to add an APNs Auth Key to your iOS project config in the Firebase console, otherwise, iOS notifications won't be delivered.
Then you will need to generate a service account key to be used in the mediator. This key contains sensitive information and should not be checked in to SCM. Follow along with the below video:
Firebase Key for Mediator
Setting up aries-mediator-service (optional)
After completing the above steps, you can now setup a local instance of
aries-mediator-service
. Clone the repo here and add the following to your.env
:A free tier ngrok account will work but only for an hour before it will need to be restarted.
After adding the above
.env
vars, run the following commands to build and run the dockerized local mediator:This will generate an invitation url in the console above the QR code. You will need to supply this URL to the BC Wallet in it's
.env
file.Setup BC Wallet
Add the following to your bc-wallet-mobile
.env
:Then build bc-wallet-mobile as usual with Android Studio or Xcode. After completing onboarding or entering your PIN, you will see a popup modal for push notifications. Select continue and then allow notifications on the resulting native popup that appears. For now, since push notifications are a developer setting, enable developer mode and toggle on push notifications.
You will now receive push notifications when your app is closed or backgrounded. You can easily test this with a Traction tenant by creating a connection to your BC Wallet, closing the app, and then sending your BC Wallet connection a message from Traction.
Notes and things to be aware of
aries-mediator-service
code, there is a constant calledMAX_SEND_RATE_MINUTES
. This is currently set to 2 and is the time needed between mediator messages in order to send a notification. This is to prevent repetitive notifications for sequential messages sent close together. We can discuss if we want to keep this behaviour but I think it's beneficial.react-native-firebase
libs: See hereAppDelegate.m
for iOS andMainActivity.java
for Android to remove all notification badges on app open. Otherwise the notifications won't be properly dismissed.Beta Was this translation helpful? Give feedback.
All reactions