I'm trying to send Push notifications to my users, and it works successfully but I'm not sure how to use the parameters that I pass it in the message itself. I'm not that experience in JS so any help would be appreciated.
我正在尝试向我的用户发送推送通知,它运行成功,但我不知道如何使用我在消息本身传递的参数。我不是那种JS经验所以任何帮助都会受到赞赏。
My Android code:
我的Android代码:
// Send push notification
final Map<String, Object> params = new HashMap<>();
params.put("userId", userId);
params.put("result", result);
params.put("username", ParseUser.getCurrentUser().getUsername());
params.put("useMasterKey", true); //Must have this line
ParseCloud.callFunctionInBackground("pushLike", params, new FunctionCallback<String>() {
public void done(String result, ParseException e) {
if (e == null) {
Log.d(getClass().toString(), "ANNOUNCEMENT SUCCESS");
} else {
System.out.println(e);
Log.d(getClass().toString(), "ANNOUNCEMENT FAILURE");
}
}
});
JavaScript Cloud Code. I'm just trying to figure out how to include the parameter variables that I've passed into the alert message itself. This doesn't work apparently:
JavaScript Cloud Code。我只想弄清楚如何包含我已经传递给警报消息本身的参数变量。这显然不起作用:
Parse.Cloud.define("pushLike", function (request, response) {
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('userId', request.params.userId);
Parse.Push.send({
where: pushQuery,
data: {
var username = request.params.userId;
var result = request.params.result;
alert: "Liked by " + username + ": " + result;
}
}, {
useMasterKey: true,
success: function () {
response.success("Success!");
},
error: function (error) {
response.error("Error! " + error.message);
}
});
});
1 个解决方案
#1
0
I changed my Cloud Code to look this this. Pushed the variables up a bit in the code and just used them like normal in the alert:
我改变了我的Cloud Code来看这个。在代码中将变量推高一点,并在警报中正常使用它们:
Parse.Cloud.define("pushLike", function (request, response) {
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('userId', request.params.userId);
var username = request.params.username;
var result = request.params.result;
Parse.Push.send({
where: pushQuery,
data: {
alert: "Liked by " + username + ": " + result
}
}, {
useMasterKey: true,
success: function () {
response.success("Success!");
},
error: function (error) {
response.error("Error! " + error.message);
}
});
});
#1
0
I changed my Cloud Code to look this this. Pushed the variables up a bit in the code and just used them like normal in the alert:
我改变了我的Cloud Code来看这个。在代码中将变量推高一点,并在警报中正常使用它们:
Parse.Cloud.define("pushLike", function (request, response) {
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('userId', request.params.userId);
var username = request.params.username;
var result = request.params.result;
Parse.Push.send({
where: pushQuery,
data: {
alert: "Liked by " + username + ": " + result
}
}, {
useMasterKey: true,
success: function () {
response.success("Success!");
},
error: function (error) {
response.error("Error! " + error.message);
}
});
});