Parse Cloud: Send Push to a single user

后端 未结 3 623
灰色年华
灰色年华 2020-12-30 14:09

I\'m using Parse and I can\'t make this method to work.

The idea is to send push to a single user with an already known user identifier from any platform within \'Cl

3条回答
  •  心在旅途
    2020-12-30 14:41

    You can join Parse.Session and Parse.Installation with a user pointer as the Session primary key, next "installationId" as the join key.

    var PushSend = function(payload, dbContact) {
        var querySession = new Parse.Query(Parse.Session);
            querySession.equalTo("user", dbContact);
            querySession.descending("updatedAt");
    
    querySession.first({ useMasterKey: true })
    
    .then(function(dbSession) {
        var installId = dbSession.get("installationId");
    
        var installQuery = new Parse.Query(Parse.Installation);
            installQuery.equalTo("installationId", installId);
    
            Parse.Push.send( {
                where: installQuery,
                data: {
                    alert: payload
                }
            }, { useMasterKey: true} )
    
            .then(function() {
                // "success"
            }, function(error) {
                // "failed"
            } );
        }, function(error) {
            // "failed"
        } );
    }
    

    The above cloud function takes as arguments :

    1. the payload text string
    2. a destination contact pointer (you have for example previously queried from Parse.User)

提交回复
热议问题