iOS - 删除 Recurring EKEvent,事件再次出现

标签 ios objective-c ekevent ekeventkit ekeventstore

我在日历中有一个重复发生的事件。我正在使用此代码删除单个事件从日历中删除。

最佳答案

在使用属性 calendarItemExternalIdentifier 的 EKCalendarItem 类引用中,您可以找到它

Recurring event identifiers are the same for all occurrences. If you wish to differentiate between occurrences, you may want to use the start date

所以你只想删除重复你必须做这样的事情:

NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendars];

NSArray *theEvents = [eventStore eventsMatchingPredicate:predicate];
NSString *recurrenceEventIdentifier;

for(EKEvent * theEvent in theEvents)
{                
    if([theEvent.eventIdentifier isEqualToString: recurrenceEventIdentifier]
        && ![eventStore removeEvent:theEvent span:EKSpanThisEvent error:&error])
    {
        NSLog(@"Error in removing event: %@",error);
    }

}

相反,您的方法只删除第一次出现的情况。如果您想删除所有重复发生的事件,只需更改 EKSpanFutureEvents 中的“span”参数即可。

编辑:现在只删除匹配的重复事件,而不是所有内容。

关于iOS - 删除 Recurring EKEvent,事件再次出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20520603/

相关文章:

ios - 在 iOS SceneKit 中更新几何表面的正确方法是什么?

ios - 如何解读 iOS 的这些崩溃报告

ios - UIButton 在旋转到横向后不起作用

objective-c - 使用适用于 iOS 的 PayPal Express Checkout 库直接付款

iphone - predicateForEventsWithStartDate 不起作用

iphone - ios - 当搜索文本为空时,UISearchDisplayDelegate 不进行搜索

ios - 从数组返回的属性创建常量

ios - 检测子层元素上的触摸

ios - EKEventKit 过去的日期事件已添加到模拟器中,但不会快速添加到设备上

iphone - EKEvent 事件标识符返回 null