在iOS中将推送通知从一个设备发送到另一个设备

时间:2017-08-27 18:25:12

标签: ios swift push-notification apple-push-notifications

我正在创建一个iOS应用程序,用户在其中订购商品,当订单准备好时,供应商应该通过推送通知通知用户。 我的问题是,是否可以将推送通知从一个设备发送到另一个设备?

为此,我想使用FCM。我读到他们允许两种消息。

  1. 下游,从服务器到设备的消息。
  2. 上游,从设备到服务器的消息。
  3. 上游消息是否会根据我的要求达到目的?如果是这样,我该如何实施呢?

1 个答案:

答案 0 :(得分:0)

我们假设您使用的是Firebase,因此对于every registered用户,有一个ssociated device token id保存到某个集合中。 (注册流程)

我们假设您使用的是cloud functions(一个模糊的定义将会运行到无服务器架构中,并且在调用时会被执行)

因此您可以通过 HTTP 通过发布方法

从您的应用中调用此功能

逻辑:

  - 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 

Voila,我确信还有其他方法可以做到这一点,但这会将您应用中的所有逻辑提取到云端。