Users can select their country and I want to my push notification only to specified group. How should I implement that? Regard the country part, should I use localstorage or sqlite is needed ?
Hi man. Localstorage did the trick for me. About push notifications, check Holly’s blog, she has made several great articles about this and I learned how to do it from there : http://devgirl.org/
1 Like
LocalStorageService.set("country", userCountry);
var tempCountry = LocalStorageService.get("country");
switch(tempCountry){
case "usa" : case "uk" : case "anyOtherCountry":
var androidConfig = {
"senderID": "replace_with_sender_id",
};
$cordovaPush.register(config).then(function(result) {
// Success
}, function(err) {
// Error
});
break;
default :
$cordovaPush.unregister(options).then(function(result) {
// Success!
}, function(err) {
// Error
});
break;
}
1 Like
To implement that properly you need to tell your server (the one that sends the Push Notifications) what country the user has selected, along with the device id/token.
Then on your server side (which has nothing to do with Ionic, really), you select only the devices having a specific country to send the PNs to.
localstorage is fine for persisting the preference on the client, though.