将推送通知发送到目标设备 [英] Sending push notifications to a targeted device

查看:100
本文介绍了将推送通知发送到目标设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个为网上商店创建的移动应用程序(iOS和Android).该应用程序的特定版本仅适用于卖方.其中有一个部分可以用作帮助台.基本上,买家可以打开门票,向卖家发送消息等.因此,我要做的就是每次买家这样做时,卖家都应该在其设备上收到推送通知.

I have a mobile app (both iOS and Android) created for an online shop. This particular version of the app is for the sellers only. There is a section in it that function as a helpdesk. Basically buyers can open tickets, send messages to sellers etc. So what I want to do is every time when a buyer does that, the seller should receive a push notification on his device.

保存买家,卖家和其他所有内容的记录的数据库在单独的服务器上运行.我可以进行某种形式的Cron工作,以定期检查购买者开立的新案件.我希望使用解析来处理推送通知.

The database that keeps records of buyers, sellers and everything else runs on a separate server. I can have some sort of a cron job to periodically check for new cases opened by buyers. I'm hoping to use Parse to handle push notifications.

现在困扰我的是如何将数据库服务器与Parse相关联.

Now where I'm a stuck at is how to associate my database server with Parse.

我目前的计划是这样的.

My current plan is something like this.

  1. 该应用已启动,卖家首次登录. Parse SDK向其服务器注册设备.除此之外,我还希望使用单独的Web服务来保存Parse生成的唯一ID(在研究中,合适的唯一ID称为安装ID ),并且在我的数据库中也记录了已登录的卖方ID.

  1. The app is launched and the seller is logged in for the first time. Parse SDK registers the device with its servers. Alongside this, using a separate web service, I was hoping to save the unique ID generated by Parse (Upon research, I found the suitable unique ID is called Installation ID) and the logged in seller's ID in my database as well.

当cron作业找到未结案件时,它会检索应该去的卖方ID.连同该安装ID.

When the cron job finds an open case, it retrieves the seller's ID that it should go to. Along with it, that Installation ID.

我的服务器发出一个HTTP请求,以使用Parse的REST API向具有该安装ID的设备发布推送通知.

My server sends out a HTTP request to post a push notification to the device with that Installation ID using Parse's REST API.

一个问题.他们尚未在 docs .

One issue. They haven't specified a way to pass an Installation ID in their docs.

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

I want to know if this is possible? Or if there is a better way to go about this?

推荐答案

可以肯定.首先,您可以通过PFInstallation获得installationId:

Pretty sure that is possible. First you can get the installationId via the PFInstallation:

PFInstallation.currentInstallation().installationId // swift

[PFInstallation currentInstallation].installationId  // Objective-C

不了解android,但可能与之类似

Dont know about android but probably similar

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

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

然后您实际上必须发送推送:查看.

And then you actually have to send the push: Take a look at the Parse REST guide under "using advanced targeting".

您可以使用如下所示的curl查询:

You can use a curl query like the following:

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的一个安装.

The important part here is the { "where": { "installationId": "%installationId%" } which sends the push message to only the Installations that match the query - exactly the one installation with the given id.

我只是尝试过,并且仅在特定设备上收到推送消息:)

I just tried and got a push message only on specific device :)

这篇关于将推送通知发送到目标设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆