iOS 8:尝试从设备日历中删除单个事件时应用崩溃

时间:2015-10-14 06:03:33

标签: objective-c ios8 ekevent ekeventstore

我使用过EKSpanThisEvent所以当我尝试从设备日历中删除单个事件时它会崩溃,而不是如果我使用EKSpanFutureEvents它不会崩溃但是它会删除具有相同eventIdentifier的所有未来事件,即使我们尝试删除单个设备日历中的事件

崩溃细节如下 断言失败 - [EKEvent _deleteThisOccurrence]
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因是:'我搞砸了日期计算中的某个地方'

我尝试了所有来源的所有解决方案,但遗憾的是没有一个是有用的,任何帮助都会得到高度赞赏

CODE

  if([identifier length] > 0)
{
    __block EKEventStore* store = [[EKEventStore alloc] init];


    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (!granted) return;

        NSDate *eventdate = [commonUnit getSystemTimeZoneDateFromDate:strdate fromFormate:@"yyyy-MM-dd"];

        NSPredicate *predicate = [store predicateForEventsWithStartDate:eventdate
                                                                endDate:[eventdate dateByAddingTimeInterval:86400]
                                                              calendars:nil];
        NSMutableArray *events = [NSMutableArray arrayWithArray:[store eventsMatchingPredicate:predicate]];
        NSPredicate *predicateidentifier = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"eventIdentifier = '%@'",identifier]];
        [events filterUsingPredicate:predicateidentifier];
        if (events.count > 0) {
            NSError* error = nil;
            [store removeEvent:events[0] span:status?EKSpanFutureEvents:EKSpanThisEvent commit:YES error:&error];
            if(error == nil)
            {
                callbackBlock(TRUE);
            }
            else
            {
                callbackBlock(FALSE);
            }
        }
    }];
}

0 个答案:

没有答案