简体   繁体   中英

Sending APN from node server to device

I have an express app that is configured to send notification to a designated device token and I am able to send and receive the notifications.

My issue is, I am currently manually sending the notifications to the device from my server by entering device token. I can fetch the token from the firebase DB that's connected to my app.

How do i send token of individual device for each event to which the db changes are made. I dont have a specific user assigned in the database(or I am not able to figure out how can the express app keep track of any user). Is there a way I can manage to fetch the particular user, Get his token and then send the desired notification. The contents of notification are present in the DB Document of user.

Can I put an observer/Listener. Or is there any other way. I am new to APNS.

PS : I am using node-apn npm for APNS connectivity.

I hope I am clear. Thanks!

You would need following:

1). A new table “device” to store all device token of users along with the following:

userId
deviceType (should be enum [“android”, “ios”])
deviceId (string, id)

2). Two api's for mobile app side:

Register a specific mobile device - Mobile App will send the “userId” and “deviceId” immediately after login in the app. Server to check if record for same “userId” and “deviceId” exists or not and if not then it has to create one in the “Device Table”

Deregister a specific mobile device - Mobile App will send the “deviceId” to free on logout from app. ( This is done because sometimes 2 different users can login the mobile app on the same device ) Back-end would delete the record for same device id.

Ultimately When you get any event to send push to a user, retrieve device token from the table and send push to that token.

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