ios - Deleting and recreating EKCalendar -


in app, create events in ekcalendar. fetch events online, , in order refresh events, want first delete calendar (if exists), recreate it, , put new events in there.

to instantiate calendar use

- (ekcalendar *)calendar {     if (!_calendar) {         nsarray *calendars = [self.store calendarsforentitytype:ekentitytypeevent];         nsstring *calendartitle = @"mycalendar";         nspredicate *predicate = [nspredicate predicatewithformat:@"title matches %@", calendartitle];         nsarray *filtered = [calendars filteredarrayusingpredicate:predicate];          if ([filtered count]) {             _calendar = [filtered firstobject];         } else {             _calendar = [ekcalendar calendarforentitytype:ekentitytypeevent eventstore:self.store];             _calendar.title = calendartitle;             _calendar.source = self.store.defaultcalendarfornewevents.source;             nserror *calendarerr = nil;             bool calendarsuccess = [self.store savecalendar:_calendar commit:yes error:&calendarerr];             if (!calendarsuccess) {                 nslog(@"calendar error = %@", [calendarerr localizeddescription]);             }         }     }     return _calendar; } 

to delete calendar, use

-(ibaction)deletecalendar{     nserror *error = nil;     [self.store removecalendar:_calendar commit:yes error:&error];  } 

both methods work fine individually. so, when start creation of events, following:

[self deletecalendar];//delete calendar , events, in case exists [self calendar];//create calendar [self importevents];//put events in calendar 

now, observe following:

on first run of app

  • a calendar created
  • events imported. (this expected, , works fine)

while app running, trigger above methods again button. following, me puzzling, result:

  • the calendar deleted (expected result)
  • no calendar created (why? main question).the "if (!_calendar)" part of method considered false, , nothing executed.
  • the 'importevents' method runs through regular hoopla, without apparent errors, although expect 'no source' error.

please advise.

update:

this indicator of happening, still don't it:

after while, events appear in different calendar, i.e. not calendar called 'mycalendar', another, icloud based calendar, apparently 1 @ point defaultcalendarfornewevents. however, doesn't make sense me.

ok, so, happening: have deleted calendar store, effectively, reference calendar still hanging around in app. solved follows:

-(ibaction)deletecalendar:(id)sender{     nserror *error = nil;     if(_calendar){         [self.store removecalendar:_calendar commit:yes error:&error];     }     _calendar = nil; } 

i hope useful someone


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -