Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send remote push notification to specific user

I created a code to send remote notification using APNs, I created a development certificate, ssl, etc. The code worked very well, when I call my php script on my server, the script send a notification and my app on my iPhone show the notification. But I have a doubt, this is a generic code, so this code will send a nofication to all iphones that has my app, but if I need to send a notification to a specific user? Like whatsapp for example? How can I inform to APNs what user that should receive the notification?

like image 227
Alexandre C. do Carmo Avatar asked Mar 08 '26 12:03

Alexandre C. do Carmo


1 Answers

You will need either a new table to handle the user_id and its device token or add a column to the user table for device token. When you send a push notification, you can then send directly to the user device token which alert the user.

Some steps that you need to prepare will be a api endpoint to allow user to PUT or POST its device token to its account. Maybe something like api/v1/user/11/token. In your iOS side, you will then just call this endpoint to send the device token to the endpoint when the permission is accept.

I would suggest a separate table to handle the token because some user have different device like android and iOS. So if you want to alert both devices, is will be a lot easier to manage.

like image 128
Zac Kwan Avatar answered Mar 10 '26 01:03

Zac Kwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!