我試圖使用雲代碼向目標渠道發送推送通知。該對象被稱爲祈禱。當有人保存禱告時,如果祈禱中的新數據不是匿名的,它應該向某些頻道發送推送通知。祈禱中有一個「匿名」鍵,它是布爾值。因此,我設置了這樣的雲代碼,以便在布爾值爲false時發送它,但如果它是true,則不會發送推送。現在的問題是,它有時會在非匿名帖子上發送推送2次。解析雲代碼發送推送通知兩次
Parse.Cloud.afterSave("Prayers", function(request) {
var firstName = request.object.get('FirstName');
var lastName = request.object.get('LastName');
var userId = request.object.get('UserId');
var anonymous = request.object.get('Anonymous');
var anonymousString = anonymous.toString
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('channels', userId);
if (anonymous == false) {
Parse.Push.send({
where: pushQuery, // Set our Installation query
data: {
alert: firstName + " " + lastName + " " + "just added a prayer request."
}
}, {
success: function() {
// Push was successful
},
error: function(error) {
throw "Got an error " + error.code + " : " + error.message;
}
});
}
});
就是這樣。我的代碼讓它保存對象兩次。謝謝! – user717452 2015-02-12 02:30:41