Add events to iCal from iPhone App, The event has no calendar set Error?

狂风中的少年 提交于 2019-12-06 13:52:03

问题


I have one problem while adding multiple events more than 70 events repeatedly again and again to the iCal from our iPhone application. First 20 events add to iCal without any issues. After the balance events not adding to iCal. The error log from the iCal shows the given

Error, ["Error Domain=EKErrorDomain Code=1 "The event has no calendar set." UserInfo=0xfada510 {NSLocalizedDescription=The event has no calendar set.}”].

Below i have attached my code. Please help me to solve this problem.

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);
}

The count maybe more than 70(sometimes it will be only 20-30 events). This code is in For loop. This code will execute nearly more than 70 times. The iCal error log displays the error "This event has no calendar set" and the eventid returns Null. How to overcome this problem. Please help me to solve this. Thanks in advance.


回答1:


Thank you so much for your responses. I have found the reason of the problem. The problem is occur only when i'm adding multiple events to iCal at a time, the EKEventStore will lost the calendar set. That is the reason the error message "Error, ["Error Domain=EKErrorDomain Code=1 "The event has no calendar set." UserInfo=0xfada510 {NSLocalizedDescription=The event has no calendar set.}”]" has came from iCal. I did a simple change in loop condition. That is, i have delayed to add an events to iCal by 3 sec's time interval for each adding events (Sorry for my poor english). This means every events will add to iCal after 3sec's delay from previous event added on iCal. Now, it seems working fine. I have tested this condition and feel good. Once again i thank you all.

Yuvaraj.M



来源:https://stackoverflow.com/questions/7977151/add-events-to-ical-from-iphone-app-the-event-has-no-calendar-set-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!