首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解析迁移-客户端向客户端推送通知

解析迁移-客户端向客户端推送通知
EN

Stack Overflow用户
提问于 2016-09-17 21:57:42
回答 1查看 123关注 0票数 0

在从Parse迁移时,我们正在尝试实现客户端到客户端推送通知。通过其他平台、讨论等,他们似乎是通过云代码来做到这一点的--这是给社区带来的几个问题-

  1. 我们必须在生产中公开主钥匙吗?
  2. 有一个场景可以使用一些他们可以共享的示例云代码:用户X类似于用户Y的对象Z...User Y将实时接收由用户X的动作触发的通知。

蒂娅。

EN

回答 1

Stack Overflow用户

发布于 2016-09-18 03:41:29

  1. 不是的。主键将仅在服务器端的云代码中使用,不会向客户端公开,因此,当您从云代码调用push api时,需要设置useMasterKey: true
  2. 为了向Y发送推送,您需要执行以下操作:
代码语言:javascript
复制
- 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:

代码语言:javascript
复制
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获取它)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39552110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档