ios - Eventkit doesn't always delete events -


i working on app, gets student's school lessons online , saves iphone's calendar.

every time lessons updated, want delete events calendar of week, , put in updated lessons whole week.

i got no problems in adding events, events don't removed?

dispatch_queue_t queue = dispatch_queue_create("com.xxxxr.xxxxxx.calendar", null);     dispatch_async(queue, ^{         ekeventstore *eventstore = [[ekeventstore alloc] init];         [eventstore requestaccesstoentitytype:ekentitytypeevent completion:^(bool granted, nserror *error) {              if (granted){                  nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults];                 ekcalendar *calendaridentifier;                  if ([defaults objectforkey:@"calendar"] == nil || ![eventstore calendarwithidentifier:[defaults objectforkey:@"calendar"]]){                     // create calendar if needed                      eksource *thesource = nil;                     (eksource *source in eventstore.sources) {                         if (source.sourcetype == eksourcetypecaldav && [source.title isequaltostring:@"icloud"]) {                             thesource = source;                             nslog(@"icloud store source");                             break;                         } else {                             (eksource *source in eventstore.sources) {                                 if (source.sourcetype == eksourcetypelocal) {                                     thesource = source;                                     nslog(@"iphone local store source");                                     break;                                 }                             }                         }                     }                      ekcalendar *cal;                     cal = [ekcalendar calendarforentitytype:ekentitytypeevent eventstore:eventstore];                     cal.title = @"xxxxxxx";                     cal.source = thesource;                     [eventstore savecalendar:cal commit:yes error:nil];                     nsstring *calendar_id = cal.calendaridentifier;                     [defaults setobject:calendar_id forkey:@"calendar"];                     calendaridentifier = cal;                  } else {                     calendaridentifier  = [eventstore calendarwithidentifier:[defaults objectforkey:@"calendar"]];                     nslog(@"calendar existed");                 }                   /* problem lies! */                 /* first delete events of week */                  nsarray *arrayofidentitiestodelete = [defaults objectforkey:@"eventidentities"];                 for(nsstring *identifierofeventtodelete in arrayofidentitiestodelete){                     ekevent *eventtoremove = [eventstore eventwithidentifier:identifierofeventtodelete];                     nserror *error;                     [eventstore removeevent:eventtoremove span:ekspanthisevent error:&error];                 }                  /* create new events 'arrayoflessons' array */                  nsmutablearray *arrayofeventidentities = [[nsmutablearray alloc] init];                  for(int dayaddingtocalendar = 0; dayaddingtocalendar < 5; dayaddingtocalendar++){                     for(nsarray *arrayofdayaddingtocalendar in [[arrayoflessons objectatindex:dayaddingtocalendar] objectatindex:3]){                          ekevent *event  = [ekevent eventwitheventstore:eventstore];                         event.calendar  = calendaridentifier;                         event.title     = [arrayofdayaddingtocalendar objectatindex:4];                         event.location  = [arrayofdayaddingtocalendar objectatindex:1];                         event.notes     = [arrayofdayaddingtocalendar objectatindex:0];                         event.startdate = [arrayofdayaddingtocalendar objectatindex:12];                         event.enddate   = [arrayofdayaddingtocalendar objectatindex:13];                         event.allday    = no;                          [eventstore saveevent:event span:ekspanthisevent error:nil];                         [arrayofeventidentities addobject:event.eventidentifier];                     }                 }                  [defaults setobject:arrayofeventidentities forkey:@"eventidentities"];              } else {                 nslog(@"not granted");             }         }];     }); 

you saying:

nserror *error; [eventstore removeevent:eventtoremove span:ekspanthisevent error:&error]; 

so throwing away error-checking. don't. @ error! that's it's for. this:

nserror *error; bool ok = [eventstore removeevent:eventtoremove span:ekspanthisevent error:&error]; if (!ok)     nslog(@"%@", error); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -