Group Group Group Group Group Group Group Group Group

How to send push notifications to a specific user?

I have read the book but when it comes to use Vapor as a server side to handle push notifications, there is no explanation on how to send notifications to one user.
What is the best way to save user device tokens, as it might have multiple devices?
What to do if a user sell his devices?
How to send push notifications when Vapor is deploy on Vapor Cloud for example?
The thing is that I can not get a path to my p8 file when my Vapor Server is deployed.

Sending to one user is the same as sending to all. Instead of pulling back all tokens from the database, just query a single one.

If a user sells his device then they will have reset it before giving it away. That means the app would have been uninstalled, and thus they no longer receive notifications. When you try to send them a push, that device token will give an error state back, and you remove that token from the database.

I’m not familiar with Vapor Cloud so I can’t help you with that, unfortunately. You’ll need to look at their docs or contact their support for help. @0xtim Do you have any insight into how to know the path to a file when deploying to Vapor Cloud?

As to multiple devices…you could link the APNS device token to that user in your database, and have a one to many relationship.

1 Like

container.make(DirectoryConfig.self).workDir will give you the current working directory of the app, from there you can append whatever you like (look at the FileMiddleware as an example)

1 Like