Issue
Developer is getting the first occurrence of the event and calling remove() on it. Although he has previously saved the event as event.save(Ti.Calendar.SPAN_FUTUREEVENTS); the future occurrences are not deleted; only the first one is. Attempt to remove the events likewise: event.remove(Ti.Calendar.SPAN_FUTUREEVENTS);
Steps
(1) Run app and allow access to Calendar
(2) Click the first button then a new ical event is added.
(3) Now press the second button in order to delete this event and all the future events related to it. However only its first occurrence is successfully deleted.
Simple sample
//Creating a recurring event with alerts
var event_added; //keep track of the event you added
function performCalendarWriteFunctions(){
var defCalendar = Ti.Calendar.defaultCalendar;
var date1 = new Date(new Date().getTime() + 3000),
date2 = new Date(new Date().getTime() + 900000);
Ti.API.info('Date1 : '+ date1 + 'Date2 : '+ date2);
var event1 = defCalendar.createEvent({
title: 'MyTests: Sample Event',
notes: 'This is a test event which has some values assigned to it.',
location: 'Appcelerator Inc',
begin: date1,
end: date2,
availability: Ti.Calendar.AVAILABILITY_FREE,
allDay: false,
});
var alert1 = event1.createAlert({
relativeOffset:-(60201000), //20 minutes before
});
var allAlerts = new Array(alert1);
event1.alerts = allAlerts;
var newRule = event1.createRecurenceRule({
frequency: Ti.Calendar.RECURRENCEFREQUENCY_MONTHLY,
interval: 2
}); // every two months
Ti.API.info('newRule : '+ newRule);
event1.recurrenceRules = [newRule];
Ti.API.info('Going to save event now');
event1.save(Ti.Calendar.SPAN_FUTUREEVENTS);
event_added = event1.id;
}
var win = Ti.UI.createWindow({
backgroundColor: 'white',
title: 'Calendar Demo',
layout:'vertical'
});
var btn1 = Ti.UI.createButton({
title:'Create event',
width:Ti.UI.SIZE, height:Ti.UI.SIZE,
top:50
});
var btn2 = Ti.UI.createButton({
title:'Delete event',
width:Ti.UI.SIZE, height:Ti.UI.SIZE,
top:30
});
win.add(btn1);
win.add(btn2);
btn1.addEventListener('click', function(e){
performCalendarWriteFunctions();
});
btn2.addEventListener('click', function(e){
var defCalendar = Ti.Calendar.defaultCalendar;
var event = defCalendar.getEventById(event_added);
Ti.API.error('event is: ' + event);
if (event != null)
{
Ti.API.info('deleting: ' + event_added);
event.remove(Ti.Calendar.SPAN_FUTUREEVENTS);
}
else
{
alert('could not delete this event because it does not exist!');
}
});
if(Ti.Calendar.eventsAuthorization == Ti.Calendar.AUTHORIZATION_AUTHORIZED) {
//performCalendarWriteFunctions();
} else {
Ti.Calendar.requestEventsAuthorization(function(e){
if (e.success) {
//performCalendarWriteFunctions();
} else {
alert('Access to calendar is not allowed');
}
});
}
win.open();
- Additional info
Object ID appears to be removed but future events are not. Device logs since simulator lacks the ability to browse the ical.
��Jun 19 11:43:21 lAlO AppLeak[743] <Warning>: [INFO] Date1 : Wed Jun 19 2013 11:43:24 GMT-0500 (CDT)Date2 : Wed Jun 19 2013 11:58:21 GMT-0500 (CDT)
��Jun 19 11:43:21 lAlO AppLeak[743] <Warning>: [INFO] newRule : [object TiCalendarRecurrenceRule]
��Jun 19 11:43:21 lAlO AppLeak[743] <Warning>: [INFO] Going to save event now
��Jun 19 11:43:29 lAlO AppLeak[743] <Warning>: [INFO] event is: [object 3C241C03-7423-44ED-8901-C70340F92B6C:C1F4CEE0-C3EB-4AA5-8D2F-5B5D6B894C9E]
��Jun 19 11:43:29 lAlO AppLeak[743] <Warning>: [INFO] deleting: 3C241C03-7423-44ED-8901-C70340F92B6C:C1F4CEE0-C3EB-4AA5-8D2F-5B5D6B894C9E
- Developer remarks
"Paradoxically, trying to delete more than once (I refer to same event id) it successfully retrieves the event for some reason, although this event has been deleted from ical..."
Reproduced issue with iPad Mini 6.1.3
PR against master : https://github.com/appcelerator/titanium_mobile/pull/4435
Backport to 3_1_X https://github.com/appcelerator/titanium_mobile/pull/4494
Verified the fix & now the future calender events do get deleted along with the current one. Thus closing. Environment: Appcel Studio : 3.1.2.201308091728 Ti SDK : 3.1.2.v20130814124556 Mac OSX : 10.8.4 Alloy : 1.2.0-beta CLI - 3.1.2-alpha Ipad4 - 6.0.1 Iphone5 - 6.0