我的應用需要雙語(英語和意大利語)。我正在通過雲代碼處理推送通知,我正在嘗試根據客戶端語言發送不同的通知。我在安裝表中創建了一個語言字段並將其保存到 [[NSLocale preferredLanguages] objectAtIndex:0];
。下面的代碼工作,但我想知道是否有另一種方式來做到這一點。我希望在查詢之前設置「alert」消息,以便我只有1個查詢。基本上我需要檢查該特定用戶的語言字段是否爲「it」,然後進行查詢。有可能或我的是唯一的解決方案嗎?用雲代碼解析推送通知語言
//push test
Parse.Cloud.afterSave("MeetingObject", function(request) {
// user owner of the meeting object
var user = request.object.get("user");
var pushQueryEn = new Parse.Query(Parse.Installation);
pushQueryEn.equalTo("user", user);
pushQueryEn.notEqualTo("language", 'it');
Parse.Push.send({
where: pushQueryEn,
data: {
alert: "English push test",
badge: "Increment",
sound: "cheering.caf",
}
}, {
success: function() {
// Push was successful
console.log(request.object.get("language"));
},
error: function(error) {
console.error("Got an error " + error.code + " : " + error.message);
}
});
var pushQueryIt = new Parse.Query(Parse.Installation);
pushQueryIt.equalTo("user", user);
pushQueryIt.equalTo("language", 'it');
Parse.Push.send({
where: pushQueryIt,
data: {
alert: "Italian push test",
badge: "Increment",
sound: "cheering.caf",
}
}, {
success: function() {
// Push was successful
console.log(request.object.get("language"));
},
error: function(error) {
console.error("Got an error " + error.code + " : " + error.message);
}
});
});
您能否添加iOS代碼? – 2017-07-25 13:24:29