1

I have one issue, if i adding event in calender through the app and if delete that added event from simuloter calendar delete button. Then it will also delete from app, is this possible? Thanks

Shubhank
  • 21,721
  • 8
  • 65
  • 83
Asmita
  • 477
  • 8
  • 20

1 Answers1

0

I am posting rough algorithm here to sync iCal events with the events stored in you app:

//model class for DB Events
@interface EventEntity 

@property(strong) NSString *eventID;
@property(strong) NSString *eventText;

@end

NSMutableArray *dbEvents; //array of EventEntity objects
NSArray *iCalEvents; //array of events fetched from iCal

NSMutableArray *eventsToDelete = [NSMutableArray array]; //We will add events in this array, needed to be deleted from db.

for(EventEntity *entity in dbEvents) {
  bool found = NO; //to keep track if this event has been found in iCal or not

 for(EkEvent *event in iCalEvents) {
    if([event.eventidentifier isEqualToString:entity.eventID]) {
    found = YES; //event is present in Cal. Ignore and break
        break;
    }
 }

   if(!found) { //If not found, it means event has been deleted from iCal. Remove it from DB.
    [eventsToDelete addObject:entity];
  }
}

//Now delete items one by one from db
for(EventEntity *entity in eventsToDelete) {

//make query something like this: Delete event where EventID = entity.eventID

//after successful deletion, remove from dbEvents
[dbEvents removeObject:entity];
}

//refresh your UI for calendar/events if needed.

Hope it helps!

Shubhank
  • 21,721
  • 8
  • 65
  • 83
NightFury
  • 13,436
  • 6
  • 71
  • 120