我试图发送推送通知,我已将我的.p12文件设置在parse-server / certs文件夹中。这是我在index.js中的代码:
Parse.Cloud.define("pushToAll", function (request, response) {
var message = request.params.message;
if (message != null && message !== "") {
message = message.trim();
} else {
response.error("Must provide \"message\" in JSON data");
return;
}
// Can see this at https://www.parse.com/apps/{APP_NAME}/cloud_code/log
var logMessage = "Sending \"{0}\" to all installations".format(message);
console.log(logMessage);
var pushQuery = new Parse.Query(Parse.Installation);
// pushQuery.containedIn("deviceType", ["ios", "android"]); // errors if no iOS certificate
// Send push notification to query
Parse.Push.send({
where: pushQuery, // Set our installation query
data: {
alert: message
}
}, {
success: function () {
// Push was successful
console.log("Message was sent successfully");
response.success('true');
},
error: function (error) {
response.error(error);
}
, useMasterKey: true});
});
我想通过云代码发送推送通知。所以这是我的main.js:
[PFCloud callFunctionInBackground:@"pushToAll" withParameters:@{@"message" : @"test"} block:^(id object, NSError *error) {
if (!error) {
NSLog(@"YES");
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Try Again !" message:@"Check your network" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}];
我在我的Xcode项目中调用它:
[Error]: {"code":1,"message":"Internal server error."} (Code: 1, Version: 1.12.0)
但这不起作用:{{1}}
在Parse.com上,我已经"安装"我的数据库中的字段:
你有什么想法吗?
答案 0 :(得分:2)
我的云代码不对,这是好的代码:
Parse.Cloud.define("pushToAll", function (request, response) {
var message = request.params.message;
console.log(message);
if (message != null && message !== "") {
message = message.trim();
} else {
response.error("Must provide \"message\" in JSON data");
return;
}
// Can see this at https://www.parse.com/apps/{APP_NAME}/cloud_code/log
// var logMessage = "Sending to all installations".format(message);
// console.log(logMessage);
var pushQuery = new Parse.Query(Parse.Installation);
// pushQuery.containedIn("deviceType", ["ios", "android"]); // errors if no iOS certificate
// Send push notification to query
Parse.Push.send({
where: pushQuery, // Set our installation query
data: {
"alert": message
}
}, {
success: function () {
// Push was successful
console.log("Message was sent successfully");
response.success('true');
},
error: function (error) {
response.error(error);
}
, useMasterKey: true});
});