How to apply notification for different intervals at single time.

You must Login before you can answer or comment on any questions.

Hello

I am creating a app.I need to create no. of notifications for different time intervals.Following is the code i am using for creating notification:-

var notification = Ti.App.iOS.scheduleLocalNotification({
    alertBody:"Breakpal was put in background",
    alertAction:"Go to Exercises",
    sound:"hello4.mp3",
    date:new Date(new Date().getTime() + 30000) // 3 seconds after backgrounding
});
I have implemented two ways:-

1)Add event listener for notification event.So create new notification on this event listner.

Ti.App.iOS.addEventListener('notification',function(){
 
var notification = Ti.App.iOS.scheduleLocalNotification({
    alertBody:"Breakpal was put in background",
    alertAction:"Go to Exercises",
    sound:"hello4.mp3",
    date:new Date(new Date().getTime() + 30000) // 3 seconds after backgrounding
});
 
});
2)The other option is creating no. of notification's at single time using loop.

None of the ways are working currently.Please suggest me how i can implement it.

Thank you.

1 Answer

Couple things here. First, 30000 ms is 30 seconds, not 3. Second, this is not going to work the way you want it to. I believe the max notifications that you're receive while doing it this way is 2. Unless you were able to memoize the creation functions. Even then, I'm not sure that you will receive more than 2 notifications.

If you want to run an interval while the app is in the background, you may want to try creating a background service to do the same thing. If you'd like to continue on your current path, you might try something like this:

function createNotification() {
    var notification = Ti.App.iOS.scheduleLocalNotification({
        alertBody:"Breakpal was put in background",
        alertAction:"Go to Exercises",
        sound:"hello4.mp3",
        date:new Date(new Date().getTime() + 3000) // 3 seconds after backgrounding
    });
 
    function nlistener(e) {
        alert('notification received');
        Ti.App.iOS.removeEventListener('notification', nlistener);
        createNotification();
    };
    Ti.App.iOS.addEventListener('notification', nlistener);
}
 
createNotification();

Your Answer

Think you can help? Login to answer this question!