I’m developing a Ionic Mobile app and I’ve just started working on my push notifications module. I’m now receiving the push notifications well, using Ionic Push Alpha and Google GCM.
My problem appears, when, inside my app, I want to let the user to configure receiving notifications or not, and receive notifications based on it’s own geolocation.
Should I send the push notification to all device tokens I have stored, and each device decide (based on the current position) if it should show the notification or not? Is that possible?
Unfortunately, the device cannot (to my knowledge) reject a push notification. Instead the setting of receiving push notifications is usually stored in a database. (In your case you would store the latitude/longitude as-well). You’d then use the REST API from whatever provider you’re using to send push notifications (As almost everybody who’s supported push notifications ever has had one)
NOTE: If your push notification provider does not have a REST API- I would recommend OneSignal. They’re free and offer great tools for push notifications. https://onesignal.com
You’d filter through the database (Using haversine formula probably to select geographical range/radius) and send a push notification through the REST API for the users that have notifications enabled.
Their may be a client-side way to do this, however I’ve always handled it on the server.