向目标设备发送推送通知

Sending push notifications to a targeted device

我有一个为在线商店创建的移动应用程序(iOS 和 Android)。该应用程序的特定版本仅供卖家使用。其中有一个部分用作服务台。基本上买家可以打开门票,向卖家发送消息等。所以我想做的是每次当买家这样做时,卖家应该在他的设备上收到推送通知。

保存买家、卖家和其他一切记录的数据库在单独的服务器上运行。我可以有某种 cron 工作来定期检查买家打开的新案例。我希望使用 Parse 来处理推送通知。

现在我遇到的问题是如何将我的数据库服务器与 Parse 相关联。

我现在的计划是这样的

  1. 应用启动,卖家首次登录。 Parse SDK 向其服务器注册设备。除此之外,使用单独的 Web 服务,我希望保存由 Parse 生成的唯一 ID(在 research 后,我发现合适的唯一 ID 称为 安装 ID)并且在我的数据库中登录的卖家 ID。

  2. 当 cron 作业找到一个未结案例时,它会检索它应该去的卖家 ID。连同安装 ID。

  3. 我的服务器使用 Parse 的 REST API.

    [=43 向具有该安装 ID 的设备发送一个 HTTP 请求 post 推送通知=]

一个问题。他们没有在 docs.

中指定传递安装 ID 的方法

我想知道这是否可能?或者是否有更好的方法来解决这个问题?

很确定这是可能的。首先你可以通过 PFInstallation:

得到 installationId
PFInstallation.currentInstallation().installationId // swift

[PFInstallation currentInstallation].installationId  // Objective-C

不知道 android 但可能相似

ParseInstallation.getCurrentInstallation().getInstallationId() // Java

https://parse.com/docs/osx/api/Classes/PFInstallation.html https://parse.com/docs/android/api/com/parse/ParseInstallation.html

发送推送

然后您实际上必须发送推送:查看“使用高级定位”下的 Parse REST guide

您可以像下面这样使用 curl 查询:

curl -X POST -H "X-Parse-Application-Id: %appId%" -H "X-Parse-REST-API-Key: %api key%" -H "Content-Type: application/json" -d '{ "where": { "installationId": "%installationId%" }, "data": { "alert": "The Giants scored a run! The score is now 2-2." } }' https://api.parse.com/1/push

这里的重要部分是 { "where": { "installationId": "%installationId%" },它将推送消息仅发送到与查询匹配的安装 - 恰好是具有给定 ID 的安装。

我刚刚尝试并仅在特定设备上收到推送消息:)