在从Parse迁移时,我们正在尝试实现客户端到客户端推送通知。通过其他平台、讨论等,他们似乎是通过云代码来做到这一点的--这是给社区带来的几个问题-
蒂娅。
发布于 2016-09-18 03:41:29
- When you create the ParseInstallation in your client code make sure that you also save the user there in a column. You need to save the user inside the ParseInstallation because your requirement is to send push to one or more users so in order to know what devices this user have (one user can have multiple devices of course) you need to save a reference to the user inside the ParseInstallation class
- Next you need to use the following code in order to send a push notification to the user:
Parse.Cloud.afterSave("SendPush", function(request) {
var query = new Parse.Query(Parse.User);
query.equalTo("objectId", "{YOUR_USER_OBJECT_ID"});
/* here you get the user by it's id. if you have another identifier or you want to use another field you can change it. You can also add multiple conditions if you like */
// here you can add other conditions e.g. to send a push to sepcific users or channel etc.
var payload = {
alert: "YOUR_MESSAGE"
// you can add other stuff here...
};
Parse.Push.send({
data: payload,
where: query
}, {
useMasterKey: true
})
.then(function() {
response.success("Push Sent!");
}, function(error) {
response.error("Error while trying to send push " + error.message);
});
});
请确保您从客户端发送用户Y的objectId。如果您没有发送,您将需要找到一种方法来获得它(也许通过从DB获取它)
https://stackoverflow.com/questions/39552110
复制相似问题