将iPhone日历事件删除与应用程序中存储的事件同步

时间:2016-05-17 15:25:45

标签: ios ekeventkit

我有一个问题,如果我通过应用程序在日历中添加事件,如果从simuloter日历删除按钮添加事件。然后它也会从应用程序中删除,这可能吗? 感谢

1 个答案:

答案 0 :(得分:0)

我在这里发布粗略算法,将iCal事件与您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.

希望它有所帮助!