I’ve been working on a react native app called Deep Connections on and off for a few years, and using it to test various technologies.
I looked into getting push notifications working within an Ionic app I had built, but just found myself struggling too much with Android Studio and Xcode configurations.
So I decided to test out the push notifications in Expo, using my Deep Connections app as a test bed. I got it working, and this is how I did it.
The Push Notifications Overview in Expo docs are pretty good.
Firstly, we need to get a user’s Expo Push Token. Modifying the code from the docs, I created a module called
registerForPushNotificationsAsync.js to include as the app starts up to get that token. And then I’ve created a minimalist function called
sendPushNotification.js to demo how to take a message and an array of Expo Push Tokens to send out the same message to every Expo Push Token.
Once I have the Expo Push Token for a user, I store it in Firebase to use later to send push notifications with. Note that you can only retrieve an Expo Push Token from a physical device. This won’t work with simulators.
Expo has a neat Push Notification Tool, that you can immediately test out push notifications with the retrieved Expo Push Token. This will work fine while you’re developing within the Expo ecosystem.
If you’re going to deploy your app to the App and Play stores some extra setup needs to be done.
To setup Expo to work with Android, follow this guide to configure Firebase Cloud Messaging, and how to upload server credentials to Expo.
And then finally to get Expo working for iOS, follow these steps.