且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

向特定用户发送远程推送通知

更新时间:2022-12-21 15:38:04

您将需要一个新表来处理 user_id 及其设备令牌,或者向用户表中添加一列用于设备令牌.当您发送推送通知时,您可以直接发送到提醒用户的用户设备令牌.

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.

您需要准备的一些步骤将是一个 api 端点,以允许用户 PUTPOST 其设备令牌到其帐户.可能类似于 api/v1/user/11/token.在您的 iOS 端,您只需调用此端点以在接受权限时将设备令牌发送到端点.

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.

我建议使用单独的表来处理令牌,因为某些用户使用不同的设备,例如 android 和 iOS.因此,如果您想同时提醒两台设备,管理起来会容易得多.

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.