我正在尝试设置推送通知后台作业。 - 运行后台作业时出现以下错误 -
E2015-02-15T21:45:23.581Z] v20:Ran job push_job: 输入:{} 失败:未调用成功/错误 这是我的代码 - 请帮我解决这个问题
Parse.Cloud.job("push_job", function(request, response) {
Parse.Cloud.define('httpRequest', function(request, response) {
Parse.Cloud.httpRequest({
method: "POST",
headers: {
"X-Parse-Application-Id": "xxxxxxxcxxxxxxxxxxxxx",
"X-Parse-REST-API-Key": "xxxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json"
},
body: {
"data": {
"alert": "Local push notification"
}
},
url: "https://api.parse.com/1/push"
}).then(function() {
response.success();
console.log("Successful push");
}, function(error) {
response.error(error);
console.log(error);
});
});
});
答案 0 :(得分:1)
Parse.Cloud.job("PushNtfct_job_TimeEnable", function(request, status) {
function dateFormat(date, format) {
// Calculate date parts and replace instances in format string accordingly
format = format.replace("DD", (date.getDate() < 10 ? '0' : '') + date.getDate());
// Pad with 0 if needed
format = format.replace("MM", (date.getMonth() < 9 ? '0' : '') + (date.getMonth() + 1));
// Months are zero-based
format = format.replace("YYYY", date.getFullYear());
return format;
}
var Today = dateFormat(new Date(), "YYYY-MM-DD")+ "T01:25:00";
// this will sent push notification at 1:25 am daily
Parse.Push.send({
channels: [ "" ],
push_time: new Date(Today),
data: {
alert: "Today's Push"
}
}, { success: function() {
console.log("Succuss with Time, Local Push notification time was sent at : " + Today);
}, error: function(err) {
console.log(err);
}
}).then(function() {
// Set the job's success status
status.success("Successfully Ran");
}, function(error) {
// Set the job's error status
status.error("damn error");
});
});