从iPhone App向iCal添加事件,该事件没有日历设置错误?

时间:2011-11-02 07:48:50

标签: iphone events calendar icalendar

我在iPhone应用程序中一次又一次地向yCal重复添加多个事件超过70个事件时遇到一个问题。前20个事件添加到iCal没有任何问题。平衡事件后不添加到iCal。来自iCal的错误日志显示给定的

  

错误,[“错误域= EKErrorDomain代码= 1”该事件没有日历   设置。“UserInfo = 0xfada510 {NSLocalizedDescription =该事件没有   日历集。}“]。

下面我附上了我的代码。请帮我解决这个问题。

int count = [eventsArray Count];
for(int i=0;i<count;i++)
{
    EKEventStore *eventStore = [[EKEventStore alloc] init]; 
    EKEvent *events = [EKEvent eventWithEventStore:eventStore];

    events.title = @"Apple";
    events.notes = @"Apple iPhone";  
    events.location = @"US";
    events.startDate = today;
    events.endDate   = tomorrow;    
    events.availability = EKEventAvailabilityFree;
    [events setCalendar:[eventStore defaultCalendarForNewEvents]];
    NSError *error;
    [eventStore saveEvent:events span:EKSpanThisEvent error:&error];
    NSLog(@"Error From iCal : %@", [error description]);

    NSString *eventId = [[NSString alloc] initWithFormat:@"%@", events.eventIdentifier];
    NSLog(@"EventID : %@", eventId);
}

计数可能超过70(有时只有20-30个事件)。 此代码在For循环中。此代码将执行近70次。 iCal错误日志显示错误“此事件没有设置日历”,并且eventid返回Null。如何克服这个问题。请帮我解决这个问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

非常感谢您的回复。我找到了问题的原因。只有当我一次向iCal添加多个事件时才会出现问题,EKEventStore将丢失日历集。这就是错误消息“Error,[”Error Domain = EKErrorDomain Code = 1“的原因。事件没有设置日历。” UserInfo = 0xfada510 {NSLocalizedDescription =该事件没有设置日历。}“]”来自iCal。我做了一个简单的循环条件更改。也就是说,我已经延迟向iCal添加一个事件,每个时间间隔为3秒添加事件(对不起,因为我的英语很差)。这意味着每次事件都会在iCal上添加上一个事件3秒延迟后添加到iCal。现在,它似乎工作正常。我已经测试了这个条件并感觉很好。再次感谢大家

Yuvaraj.M