gpt4 book ai didi

parse-platform - 解析云 : Send Push to a single user

转载 作者:行者123 更新时间:2023-12-04 04:32:51 25 4
gpt4 key购买 nike

我正在使用 Parse,但无法使此方法起作用。

这个想法是从“云代码”中的任何平台向具有已知用户标识符的单个用户发送推送。

我尝试过的查询没有推送给该用户(实际上没有推送给任何用户)

  • 通过用户指针进行PFInstallation:
    var targetUser = new Parse.User();targetUser.id = userID;var query = new Parse.Query(Parse.Installation);query.equalTo('user', targetUser);
  • 在 PFUser 本身中查询
    var query = new Parse.Query(Parse.User);query.equalTo('objectId', userID);

  • 该方法的完整代码:
    Parse.Cloud.define("sendPushContactUser", function(request, response) {

    // Get parameters
    var userID = request.params.userID; // I'm obviously passing this parameter in the method call


    // Query
    /* ------ query = Any of the above options ------ */


    Parse.Push.send({
    where: query,
    data: {
    title : "New message",
    alert : "User message",
    badge : "Increment",
    sound : "soundNotifUserContact.caf",
    "params" : {
    "pushType" : 2,
    "userID" : userID
    }
    }
    }, {
    success: function() {
    response.success();
    },
    error: function(error) {
    response.error(error);
    }
    });

    });

    感谢您的时间和帮助。

    最佳答案

    这对我来说效果很好,但是您必须在之前将您的用户与您的安装链接起来:

    var query = new Parse.Query(Parse.User);
    query.equalTo('username', 'Sento');
    // Find devices associated with these users
    var pushQuery = new Parse.Query(Parse.Installation);
    // need to have users linked to installations
    pushQuery.matchesQuery('user', query);


    Parse.Push.send({
    where: pushQuery,
    data: {
    aps: {
    alert: "Test",
    sound: ""
    }
    }
    }, {
    success: function () {
    response.success("Hello world!");
    },
    error: function (error) {
    response.error(error);
    }
    });

    关于parse-platform - 解析云 : Send Push to a single user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26040437/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com