Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add event to calendar IOS7 with my app

i'm trying to build an app that would add events to the default calendar in IOS 7. First i added a framework: EventKit.Framework and imported it in 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 it gives me this error when i run this on my iPhone

Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"

do you know what can i do?

like image 998
r4id4 Avatar asked Oct 11 '13 11:10

r4id4


People also ask

How do I automatically add events to my Apple calendar?

Tap Mail, Contacts, Calendars. Scroll down and found Events Found in Mail. Toggle it on for automatic mail events added to Calendar app and off for manual input.

How do I import an event into my iPhone Calendar?

Click on the Calendar icon on the panel on the left. If you have already set up calendar events on your iPhone, they will now be displayed within the main program window. Now, click on the Import calendars button and navigate to the location where you saved your Google calendars. Then click Open.


2 Answers

First of all, you must initialize your EventStore and then request access to use the user’s Calendar database with the following method:

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

See the AppleDocumentation

Hope it helps.

like image 154
TiagoPereira17 Avatar answered Sep 30 '22 04:09

TiagoPereira17


try using requestAccessToEntity it will resolve your problem.

like image 24
Deepak Singh Avatar answered Sep 30 '22 03:09

Deepak Singh