简体   繁体   中英

Push Notification to specific firebase user by Expo managed workflow

I am new in react-native android application. I have created an Expo project (managed workflow) and I'm searching about how to send notification to a specific user that I select from a picklist in my android application but I found only the example of how to push notifications to all who installed an app.

Can I push notification to specific user in the firebase project using expo managed workflow? or I have to only create java android project to do that?

Here is how the flow can be done. What you need to do is, make api that saves every user's ExpoToken ExponentPushToken[xxxxxxxxxxxx-xxxxxxxx] in db against that user's id Expo notification doc , probably upon login. Then make a separate api for sending notification to a specific user. When any user is selected, call the api and send that user's id and message (if any), then in backend fetch that user's ExpoToken from db by the id recieved. After that simply make a post request to this api https://exp.host/--/api/v2/push/send , the request body would be like:

{
    "to": "ExponentPushToken[xxxxxxxxxxxx-xxxxxxxx]",
    "sound": "default",
    "body": "You message"
}

More on this here . And when you need to generate standalone apk for the app, you first need to connect it to firebase to work out. Here Using Firebase Cloud Messaging for Expo. Hope you got it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM