Adding Event to Native calendar in iOS

Add Eventkit framework to your project

//Code Snippet:

EKEventStore *store;

store=[[EKEventStore alloc] init];

//for iOS 7.0 and above we need to have the permission of user for using eventkit that is the calendar

//ask for permission:

[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)

{

// handle access here

if(granted)

{

//configure event:

EKEvent *addNewEvent=[EKEvent eventWithEventStore:store];

addNewEvent.startDate=fromDate;

addNewEvent.endDate=toDate;

EKCalendar *defaultCalendar=[store defaultCalendarForNewEvents];

addNewEvent.calendar=defaultCalendar;

EKRecurrenceRule *recRule=[[EKRecurrenceRule alloc] init];

addNewEvent.recurrenceRules=[NSArray arrayWithObject:recRule];

 

BOOL status= [store saveEvent:addNewEvent span:EKSpanThisEvent commit:YES error:&error];

if(status)

{

NSLog(@”Successfully saved”);

}

else

{

//error in saving

//                NSLog(@”error in saving: %@”,error);

}

}

}

];

 

 


Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at info@nanostuffs.com, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box