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?
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.
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.
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.
try using requestAccessToEntity it will resolve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With