ios - 从 iPhone 日历中删除所有 future 重复发生的事件

标签 ios objective-c iphone

谁知道如何从 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 日历中删除所有 future 的事件。

谢谢!

最佳答案

我自己找到了解决方案。

为了删除所有 future 的事件,我正在使用此代码

EKEventStore* store = [[EKEventStore alloc] init] ;
EKEvent* eventToRemove = [store eventWithIdentifier:strIdentifier];
if (eventToRemove != nil) {
    NSError* error = nil;
    [store removeEvent:eventToRemove span:EKSpanFutureEvents error:&error];
}

要删除当天条目,我们必须使用“EKSpanThisEvent”,要删除 future 事件,我们必须使用“EKSpanFutureEvents”

关于ios - 从 iPhone 日历中删除所有 future 重复发生的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25480045/

相关文章:

ios - Objective-C - 简单数学的错误输出

objective-c - 如何在 View Controller 而不是应用程序委托(delegate)中创建选项卡栏 Controller ? IOS 4.1

ios - Swift3 scheduledTime秒数运行太快时计时时间较长

ios - 根据条件导航到不同 View Controller 的按钮

ios - 如何将 "C++ completion handler"传递给 NSURLSessionDataTask 来处理它返回的数据?

iphone - 新iPad是否支持Core Bluetooth,还是仅限于iPhone 4S?

iphone - 为什么我收到 "implicit declaration of function ' Perform XML XPath Query'"警告?

iphone - iOS(iPad、iPhone)有环回接口(interface)吗?

ios - Uitableview 在 sectionIndexTitles 中使用哈希符号排序

ios - 模态视图 Controller subview