Gopinath
Gopinath

Reputation: 5442

The Event has no Calendar set error occured while adding to iCal from iPhone app?

Am new to iPhone App development. Now, am struggling with adding event to iCal from iPhone application. The problem is While adding More than 70 events(Repeated events) to iCal the events has not add in iCal. The iCal through the Error message is ["Error Domain=EKErrorDomain Code=1 "The event has no calendar set." UserInfo=0xfada510 {NSLocalizedDescription=The event has no calendar set.}”]. How to solve this problem? Can you please guide me to solve this problem? Where i'm doing wrong? Thanks is advance.

This is my code...

EKEventStore *eventStore = [[EKEventStore alloc] init]; 
EKEvent *events = [EKEvent eventWithEventStore:eventStore];

events.title = @"Title";
events.notes = @"Descriptions";  
events.location = @"Location";
events.startDate = DATE;
events.endDate   = endDates;    
events.availability = EKEventAvailabilityFree;
[events setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:events span:EKSpanThisEvent error:&err];
NSLog(@"Error From iCal : %@", [err description]);

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

Sometimes the eventID is return null and The [err description] shows the Error ["Error Domain=EKErrorDomain Code=1 "The event has no calendar set." UserInfo=0xfada510 {NSLocalizedDescription=The event has no calendar set.}”]. How to solve this ? Any ideas? Thanks for spending your valuable time with me...

Upvotes: 0

Views: 1342

Answers (1)

Jazzmine
Jazzmine

Reputation: 1875

Don't know if you've solved this problem in the meantime but if not, it looks like you need to find and assign a calendar first such as below:

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

EKCalendar *targetCalendar = nil;
targetCalendar = [eventStore defaultCalendarForNewEvents];

if (targetCalendar == nil){
    NSLog(@"The target calendar is nil.");

    //do an alert with only an OK - test this

    [eventStore release];
    return;
}   

NSLog(@"The target calendar is %@.", targetCalendar);

Upvotes: 1

Related Questions