0

Example: Schedule a notification for 15 minutes and save the user's location.

If the user leaves radius, the notification will not be sent.

Would it be possible to do this using onesignal or just with cordovaLocalNotification?

var notificationObj = {
                contents: {
                    en: "asdasdasd"
                },
                include_player_ids: [playerId],
                send_after: "2017-02-15 20:42:00 GMT-0200",
            }

window.plugins.OneSignal.postNotification(notificationObj,
    function(successResponse) {
        console.log("Notification Post Success:", successResponse);
    },
    function (failedResponse) {
        console.log("Notification Post Failed: ", failedResponse);
        alert("Notification Post Failed:\n" + JSON.stringify(failedResponse));
        }
    )
 })

Before that I would save the current location and at the time of sending I would compare if the location is within the 1km radius. If yes, I would send it if not, I would not send

Gansonic
  • 347
  • 4
  • 15

1 Answers1

1

There are two types of notifications: local notifications and push notifications. Local notifications work like an alert (i.e. I want to be awaked at 9AM) and they can be saved and launched locally, without any internet connection, at the specified time. For this kind of notifications, you can use the Local Notifications plugin. The second case, Push Notifications, are sent (basically...) from your server to the user app via internet suitably a kind of notification rules set server side. So, for you specific case, if I got your needs, you can:

  1. get your actual location and timing, send all these data to your server
  2. save (server side) these data and set a timing (15 mins) to send a push notification
  3. after 15 mins, without info from the client app, send the push notitication.

If the user leave the circle radius, send a message to your server, telling "I'm out of the circle, don't send me the push notification". You can decide, server side, to stop the further notification sending.

So, for your case, I would just use Push Notifications.

Little drawback: if the user looses connection and leaves the circle, the client message would not be sent to the server and the server would not be alerted about that, so it'll send the notification to the user. Anyway you can manage, client side, this case to avoid it.

Edit: you can also manage everything using Local Notifications as alerts and don't use Push Notifications at all, as you wish. I would not use both systems.

Zappescu
  • 1,429
  • 2
  • 12
  • 25