My app needs to be bilingual (english and italian). I'm working on push notifications through cloud code and i'm trying to send different notifications based on the client language. I created a language field in the Installation table and saved to it the
[[NSLocale preferredLanguages] objectAtIndex:0];
. The code below works but i wonder if there is another way to do it. I would prefer to set the "alert" message before the query so that i would have only 1 query. Basically i need to check if the language field for that particular user is "it" or not and then make the query. Is it possible or mine is the only solution?
//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);
}
});
});