任何人都知道如何从iPhone日历中删除重复发生的事件吗?
我将此代码用于每周重复的商店活动。
EKEventStore *eventSotre = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventSotre];
EKRecurrenceRule *recurrenceRule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyWeekly interval:1 end:nil];
[event addRecurrenceRule:recurrenceRule];
[event setCalendar:[eventSotre defaultCalendarForNewEvents]];
event.title= @"EventTitle";
NSDate *duedate = [NSDate date];
event.startDate =duedate;
event.endDate= duedate;
NSArray *arrAlarm = [NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:duedate]];
event.alarms= arrAlarm;
NSError *err;
BOOL isSuceess=[eventSotre saveEvent:event span:EKSpanThisEvent error:&err];
strIdentifier = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier];;
if(isSuceess){
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Event" message:@"Event added in calendar" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertview show];
}
else{
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Event" message:[err description] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertview show];
}
现在我想删除iPhone日历中的所有未来事件。
谢谢!
答案 0 :(得分:3)
自己解决方案。
要删除我正在使用此代码的所有未来事件
EKEventStore* store = [[EKEventStore alloc] init] ;
EKEvent* eventToRemove = [store eventWithIdentifier:strIdentifier];
if (eventToRemove != nil) {
NSError* error = nil;
[store removeEvent:eventToRemove span:EKSpanFutureEvents error:&error];
}
对于删除当前日期条目,我们必须使用" EKSpanThisEvent"并删除未来事件,我们必须使用" EKSpanFutureEvents"