Notifications in React Native
You can use a Firebase Cloud Messaging server and an example push notification server to enable the xmtp-react-native example app to send push notifications.
Perform this setup to understand how you might want to enable push notifications for your own app built with the xmtp-react-native SDK.
Set up a Firebase Cloud Messaging server
For this tutorial, we'll use Firebase Cloud Messaging (FCM) as a convenient way to set up a messaging server.
Create an FCM project.
Add the example app to the FCM project. This generates a
google-services.jsonfile that you need in subsequent steps.Add the
google-services.jsonfile to the example app's project as described in the FCM project creation process.Generate FCM credentials, which you need to run the example notification server. To do this, from the FCM dashboard, click the gear icon next to Project Overview and select Project settings. Select Service accounts. Select Go and click Generate new private key.
Run an example notification server
Now that you have an FCM server set up, take a look at the export-kotlin-proto-code branch in the example-notifications-server-go repo.
This example branch can serve as the basis for what you might want to provide for your own notification server. The branch also demonstrates how to generate the proto code if you decide to perform these tasks for your own app. This proto code from the example notification server has already been generated in the xmtp-android example app.
To run a notification server based on the example branch:
Clone the example-notification-server-go repo.
Complete the steps in Local Setup.
Get the FCM project ID and FCM credentials you created earlier and run:
YOURFCMJSON=`cat YOURFIREBASEADMINFROMSTEP4.json`dev/run \
--xmtp-listener-tls \
--xmtp-listener \
--api \
-x "production.xmtp.network:5556" \
-d "postgres://postgres:xmtp@localhost:25432/postgres?sslmode=disable" \
--fcm-enabled \
--fcm-credentials-json=$YOURFCMJSON \
--fcm-project-id="YOURFCMPROJECTID"You should now be able to see push notifications coming across the local network.
Update the Android example app to send push notifications
Add your
google-services.jsonfile to theexample/android/appfolder if you haven't already done it as a part of the FCM project creation process.Uncomment
apply plugin: 'com.google.gms.google-services'in the example app'sbuild.gradlefile.Uncomment
classpath('com.google.gms:google-services:4.3.15')in the top level of the example app'sbuild.gradlefile.Sync the gradle project.
Replace
YOUR_SERVER_ADDRESSin thePullController.tsfile. If you're using the example notification server, it should be something likeYOURIPADDRESS:8080since the Android emulator takes over localhost.Change the example app's environment to
productionin both places inAuthView.tsx.Replace
YOUR_FIREBASE_SENDER_IDin thePullController.tswith your sender ID from Firebase.
Update the iOS example app to send push notifications
Coming soon.