Click here to Skip to main content
Click here to Skip to main content

EventKit Framework for iPhone Calendar

By , 4 Mar 2012
 

Introduction

Accessing iPhone native calendar from the appliation and add a custom event to the calendar along with reminder alert.

Requirement

There is a requirement in an application that app is able to add an event to the iPhone native calendar along with alert. I created this in my demo application and then added to the main application. I am sharing a part of code here.

The code - How to use?

First add Event Kit Framework to you application. The Event Kit framework provides classes for accessing and modifying calendar event information.

NSString *str=@"This is Your Event title";

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

EKEvent *event = [EKEvent eventWithEventStore:eventStore];

event.title = str;

event.startDate = [[NSDate alloc] initWithTimeInterval:timeint sinceDate:date];
This is startdate and time of the event we can set by using date time fucntions to calulate and set this.

event.endDate = [[NSDate alloc] initWithTimeInterval:1800 sinceDate:event.startDate];
Similarly this is event's end date and time

NSTimeInterval interval = 60* -min;
This is the time at which you can see the native calendar alert. Note that here i write (-min) this indicates that alert will show before event time otherwise it will appear after event start time

EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:interval]; //Create object of alarm

[event addAlarm:alarm]; //Add alarm to your event

event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
// Add event to iPhone Calendar

Uses

You can use this code to add reminder or alert to iPhone native calendar using custom application same as anyone can do adding an event directly to the iPhone Calendar.

Feel free to contact me any help on this.


Thanks

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

iphonish
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 5 Mar 2012
Article Copyright 2012 by iphonish
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid