Notification Schedule and update error

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

Hi, I'm building an app to register progress in goals, I schedule a notification to indicate the progress, when you click in progress and return to the app it must update the goal and create a new notificacion, but it creates a cycle showing the alerts in the code, like I was creating n number of notifications and updates

//app.js
Ti.App.iOS.addEventListener('notification', function(e){
    functions.addProgress(e.userInfo.id);
    functions.createNewNotification(e.userInfo.id,e.userInfo.title,e.userInfo.date,e.userInfo.endDate,e.userInfo.days)
});
//notifications.js
functions.createNewNotification=function(id,title,date,endDate,days){
        if(date.getTime()<endDate.getTime()){
            var notification = Ti.App.iOS.scheduleLocalNotification({
                alertBody:title,
                alertAction:"¿Progresaste?",
                userInfo:{"id":id, "date":date,"title":title,"days":days,"endDate":endDate},
                date:date,
                titleN:title,
                idN:id,
                daysN:days,
                endDateN:endDate 
            });
            notifications[cont++]=notification;
            alert('Creada');
        }
 
    }
    functions.addProgress=function(id){
        var db=Titanium.Database.open('meta');
        db.execute('CREATE TABLE IF NOT EXISTS goals(idGoal INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT,initDate INTEGER, endDate INTEGER,progress INTEGER, alerts INTEGER,contact TEXT);');
        var goals=db.execute('SELECT * FROM goals WHERE idGoal='+id+';');
        var progress=0;
        while(goals.isValidRow()){
            var initDate =Date.parse(goals.fieldByName('initDate'));
            var endDate =Date.parse(goals.fieldByName('endDate'));
            var alerts = goals.fieldByName('alerts');
            var contact = goals.fieldByName('contact');
 
            var ONE_DAY = 1000 * 60 * 60 * 24
            var date1_ms = initDate.getTime();
            var date2_ms = endDate.getTime();
            var date3_ms = new Date().getTime();
            var difference_ms = Math.abs(date2_ms - date1_ms);
            var days=Math.round(difference_ms/ONE_DAY);
            var difference2_ms = Math.abs(date3_ms - date1_ms);
            var daysPassed=Math.round(difference2_ms/ONE_DAY);
 
            var alertsDay=days/alerts;
            var alertsPassed=daysPassed/alertsDay;
            progress=(alertsPassed*100)/alerts;
 
            goals.next();
        }
        db.execute("UPDATE goals SET progress="+progress+" WHERE idGoal="+id+";");
        db.close();
        alert('Actualizado');
    }

Your Answer

Think you can help? Login to answer this question!