0

我正在开发一个应用程序,当用户将任何事件添加为他的最爱时,我将该事件添加到 iCal 但是如果用户从他的最爱中删除该特定事件,我如何从 iCal 中删除该事件。

这是我的代码:

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[[self.parentDetailArray valueForKey:@"start_time_num"] intValue]];
            NSDateFormatter *dateformatter=[[NSDateFormatter alloc]init];
            [dateformatter setLocale:[NSLocale currentLocale]];
            [dateformatter setDateFormat:@"dd-MM-yyyy"];
            NSString *dateString=[dateformatter stringFromDate:date];

             EKEventStore *eventStore = [[EKEventStore alloc] init];

             if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) 
{
 [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
             if (granted){
             //---- codes here when user allow your app to access theirs' calendar.

             EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
             event.title     = title;
             event.startDate = date;
             event.endDate   = [[NSDate alloc] initWithTimeInterval:1000 sinceDate:event.startDate];

             [event setCalendar:[eventStore defaultCalendarForNewEvents]];
             NSError *err;
             [eventStore saveEvent:event span:EKSpanThisEvent error:&err];

// Here I'm trying to get the identifier of that event but m getting only (null)
             self.str = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier];
             [self.arrayofEventId addObject:self.str];

             //[self performCalendarActivity:eventStore];
             }else
             {
             //----- codes here when user NOT allow your app to access the calendar.
             }
             }];
             }
             else {
             //---- codes here for IOS < 6.0.
             EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
             event.title     = @"Testing for calendar";

             event.startDate = [[NSDate alloc] init];
             NSLog(@"%@",event.startDate);
             [event setCalendar:[eventStore defaultCalendarForNewEvents]];
             NSError *err;
             [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
             //[self performCalendarActivity:eventStore];
             }

如何获取事件标识符 n 从 iCal 中删除该特定事件。任何帮助,将不胜感激。

4

1 回答 1

1

您可以将所有应用程序生成的事件 ID 写入文件,然后在下次加载应用程序时重新加载它们。通过这种方式,您可以跟踪您的应用创建了哪些事件。那么你可能想试试这个方法:

- (BOOL)removeEvent:(EKEvent *)event span:(EKSpan)span commit:(BOOL)commit error:(NSError **)error

用这个保存:

NSString *id = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier];

用这个删除:

EKEvent *event = [eventStore eventWithIdentifier:id];

NSError *error = nil;
[eventStore removeEvent:event span:EKSpanThisEvent error:&error];

Apple 在此处有关于 EKEventStore 的文档。

于 2013-06-26T19:05:33.320 回答