在 iOS 内将推送通知从一台设备发送到另一台设备
Sending push notifications from one device to another in iOS
我正在创建一个 iOS 应用程序,用户在其中订购商品,当订单准备就绪时,供应商应该通过推送通知通知用户。
我的问题是,是否可以将推送通知从一台设备发送到另一台设备?
为此,我想使用 FCM。我读到他们允许两种消息。
- 下游,从服务器到设备的消息。
- 上游,从设备到服务器的消息。
上游消息能达到我的要求吗?如果是这样,我应该如何实施它们?
假设您使用的是 Firebase
,因此对于 every registered
用户,有一个关联的 device token id
保存到某些 collection 权限。 (注册流量)
假设您使用的是 cloud functions
(一个模糊的定义是 运行 进入无服务器架构的函数,它们在调用时执行)
因此您可以通过 HTTP 使用 Post 方法
从您的应用程序调用此函数
逻辑:
- extract that http request
- who is sending the message (uid, message)
- who needs to receive that message (someone)
- query that someone's device token id and save it to recipient_device_token_id
- construct to push notification payload (message)
- send push notification for recipients using its recipient_device_token_id
- end the http response
瞧,我相信还有其他方法可以做到这一点,但这会将所有逻辑从您的应用程序提取到云端。
我正在创建一个 iOS 应用程序,用户在其中订购商品,当订单准备就绪时,供应商应该通过推送通知通知用户。 我的问题是,是否可以将推送通知从一台设备发送到另一台设备?
为此,我想使用 FCM。我读到他们允许两种消息。
- 下游,从服务器到设备的消息。
- 上游,从设备到服务器的消息。
上游消息能达到我的要求吗?如果是这样,我应该如何实施它们?
假设您使用的是 Firebase
,因此对于 every registered
用户,有一个关联的 device token id
保存到某些 collection 权限。 (注册流量)
假设您使用的是 cloud functions
(一个模糊的定义是 运行 进入无服务器架构的函数,它们在调用时执行)
因此您可以通过 HTTP 使用 Post 方法
从您的应用程序调用此函数逻辑:
- extract that http request
- who is sending the message (uid, message)
- who needs to receive that message (someone)
- query that someone's device token id and save it to recipient_device_token_id
- construct to push notification payload (message)
- send push notification for recipients using its recipient_device_token_id
- end the http response
瞧,我相信还有其他方法可以做到这一点,但这会将所有逻辑从您的应用程序提取到云端。