Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two or more Notifications using Cordova Local Notification #1076

Closed
eliacimdavila opened this issue Aug 16, 2016 · 3 comments
Closed

Add two or more Notifications using Cordova Local Notification #1076

eliacimdavila opened this issue Aug 16, 2016 · 3 comments

Comments

@eliacimdavila
Copy link

Hi.

I am trying to make a itinerary with a list of events (12 or more), all in the same day but with different hour. I want to add a Reminder Button, and when the user tap in it, create a Notification that will be sent 10 minutes before the every event hour that user choose. I the same way, if the user tap again in the same event, cancel the previous notification. My function code is:

$scope.addAlert = function(hour, event){
    var hourid = hour.alterid;
    $ionicLoading.show();

    $cordovaLocalNotification.isScheduled(hourid).then(function(isScheduled) {
      if(isScheduled){
        $cordovaLocalNotification.cancel(hourid)
                                 .then(function(){
                                   event.target.className = "icon ion-ios-bell";
                                   $ionicLoading.hide();
                                 });
      }
      else{
        var alertDate = new Date($scope.date + ' ' + hour.horaini);
        alertDate.setMinutes(alertDate.getMinutes() + parseInt(hour.alerthour));

        $cordovaLocalNotification.add({
            id: hourid,
            date: alertDate,
            message: hour.alert,
            title: "CISI 2016",
            autoCancel: true,
            sound: "file://sound/chime_bell_ding.wav"
        }).then(function () {
          event.target.className = "icon ion-ios-bell-outline";
          $ionicLoading.hide();
        });
      }
    });
  };

Basically, first I get the ID of the event selected, second I use cordovaLocalNotification.isScheduled() to determine if the Notification for that event is already scheduled, in base on that id. If that function return me true, I cancel the event. If return me false, I create the new alert, with the id. Every event has different Id, different hour and differente message.

So, the first time I tap in the reminder, it works fine. When is only one, the notification is created, and is sent in the correct. But, if I tap the first event, and after tap a second one, here occurs something weird. cordovaLocalNotification.isScheduled() return true, in other words, that the notification is already scheduled, and the code cancel it, but what it does, in fact, is cancel the first one.

The two events have different ID, but it's look like anyway the application take every notification as the same. What I am doing wrong? What is the correct form of add two or more notifications?

Thanks.

@LeandroFranciscato
Copy link

Good question @eliacimdavila, I don't have idea and I tried it a lot.
Hope from help.

@rwillett
Copy link
Collaborator

If this is still a problem, please update with the template in #1188.

@rwillett
Copy link
Collaborator

rwillett commented Mar 5, 2017

Closed as no update from original poster.

@rwillett rwillett closed this as completed Mar 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants