Delay in Localnotifications


#1

Hi

I wanted to now if it’s normal that sometimes the local notifications you schedule are delayed (only on IOS).
I’ve scheduled one every 5 seconds, but the first one comes in 90seconds.

            var count = 1;
            var now = new Date().getTime(),
             day = new Date(now + 5 * 1000);
        for (var i = 0; $scope.notificationsPerCoach.length; i++) {
            $cordovaLocalNotification.schedule({
                id: count,
                title: 'Hey ' + $scope.data.name,
                text: $scope.notificationsPerCoach[i].content,
                at: new Date(now + 60 * 60 * 24 * 1000 * count),
                icon: "file://" + coach.name + ".png"
            });

            count += 2;
        }

Is it normal or is there something wrong with my code?

Kind regards


#2

Have you tried using it in settimeout function?


#3

No, how can i do that?


#4

This should do it:

setTimeout(function(){
    $cordovaLocalNotification.schedule({
        id: 1,
        title: 'Warning',
        text: "You're so sexy!",
        data: {
            customProperty: 'custom value'
        }
    }).then(function (result) {
        console.log('Notification 1 triggered');
    });
}, 5000);

#5

This should do it:

var now = new Date().getTime();

for (var i = 0; i < $scope.notificationsPerCoach.length; i++) {
  $cordovaLocalNotification.schedule({
    id: i,

    // 1. Are you sure you don't have something like $scope.notificationsPerCoach[i].name ?
    title: 'Hey ' + $scope.data.name, 
    text: $scope.notificationsPerCoach[i].content,
    at: new Date(now + 5000 * i),
    icon: "file://" + coach.name + ".png" // same as 1.. 
  });
}

#6

Just a side note, on both platform documentations it’s noted that notifications are not accurate and may not be as real time as you want, especially if a phone is getting multiple at the same time (remote and local). Just keep that in mind while testing :slight_smile: Most of my in my app are almost spot on, sometimes they’re a couple seconds off.

Cheers!