Add event to IOS7 calendar with my application

I am trying to create an application that will add events to the default calendar in iOS 7. First I added the framework: EventKit.Framework and imported it into my .m

this is my code:

- (void)AddEventToCalendar { EKEventStore *eventStore = [[EKEventStore alloc] init]; EKEvent *event = [EKEvent eventWithEventStore:eventStore]; // title of the event event.title = @"Event"; // star tomorrow event.startDate = [[NSDate date] dateByAddingTimeInterval:86400]; // duration = 1 h event.endDate = [[NSDate date] dateByAddingTimeInterval:90000]; // set the calendar of the event. - here default calendar [event setCalendar:[eventStore defaultCalendarForNewEvents]]; // store the event NSError *err; [eventStore saveEvent:event span:EKSpanThisEvent error:&err]; } 

but he gives me this error when I run it on my iPhone

Domain Error = EKCADErrorDomain Code = 1013 "Operation could not be completed (EKCADErrorDomain error 1013.)"

Do you know what I can do?

+6
source share
2 answers

First of all, you must initialize your EventStore, and then request access to use the User Calendar database in the following way:

 [yourEventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { if(granted) { // create/edit your event here }]; 

See AppleDocumentation

Hope this helps.

+4
source

try using requestAccessToEntity , it will solve your problem.

+3
source

Source: https://habr.com/ru/post/955757/


All Articles