Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Parse Cloud Code in Conjunction with .NET SDK

Objective:

  • When a table is updated with a new row (ParseFile + ParseUser + ParseUser), send one of the ParseUsers a push notification
  • When a new user is created, add a new row to a table (ParseFile + user)

Can either of these be easily achieved without jumping through some major hoops? I'm completely unfamiliar with Cloud Code, though I tried to read through some of the documentation. Cloud Code looks like it has the potential to perform this task, but I haven't seen any examples of doing something like I would like to do.

Does anyone have concrete examples of using Parse Cloud Code in conjunction with the .NET SDK and table updates?

like image 824
pierceboggan Avatar asked Apr 24 '26 00:04

pierceboggan


1 Answers

Parse has a nice Documentation: Parse CloudCode

This is an example Code, which sends a push every time a user is created

//instead of Parse.User you can use any custom parse class too, but write them inside quotes
Parse.Cloud.afterSave(Parse.User, function(request) {
    if(!request.object.existed()){//existed() returns false if the object was just created
        var query = new Parse.Query(Parse.Installation);
        query.equalTo("User", request.object);
        Parse.Push.send({
            where: query,
            data: {
                badge: "Increment",
                alert: "Welcome " + request.object.get("username"),
                sound: "beep.caf"
            }
        }, {
            success: function(){
                //succeed
            },
            error: function(err){
                console.error("Got an error " + error.code + " : " + error.message);
            }
        });
    }
});

There are also other hooks available:

  • beforeSave
  • afterSave
  • beforeDelete
  • afterDelete

Inside these hooks you can send push notifications, create new objects, manipulate objects, do nearly whatever you want.

In Parse CloudCode you can take advantage of the Parse JavaScript API.

like image 101
latonz Avatar answered Apr 26 '26 15:04

latonz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!