12 Sep 2017

Add event to device calendar in iOS using Swift


Add event to device calendar in iOS using Swift

Introduction to Event-Kit framework:

As per the post heading, create events in calendar using swift. This tutorial is revolving around EventKit framework which comes as default bundled with Xcode. The EventKit framework provides classes for accessing and manipulating calendar events and reminders. Thus, we can add event to ios device calendar app using classes provided in EventKit framework in swift language. In this tutorial we will learn how to create event in calendar app of iPhone or calendar app of the iPhone from within our own app  programmatically using swift language.

Looking for objective C version then please visit Add event to device calendar - Objective C

Steps for creating event to iPhone device calendar app


Step 1: Add EventKit framework under Linked Frameworks and libraries


Step 2: Create Event store object


Step 3: In info.plist file add privacy policy key for calendar usage, as shown in below image other wise your app will crash as soon as you want to access device calendar

Add privacy policy key for accessing device calendar in info.plist

Step 4:  Create a function having three parameter's

1) Event Title - This is the title of the event we want to show in device calendar.
2) Event Start date - This is the event start date.
3) Event end date - This is the event end date.

 Inside the function we, will first request for access to device calendar. On successful access to device calendar, we will use EKEvent class to create and event on device calendar and EKAlarm class to set an alarm or reminder for the event.


Where to go from here:

In this tutorial we learned about how to create event to native calendar app of iPhone in iOS using EventKit framework. Also we learned how to set alarm for our events created from our own app on iPhone default calendar app. For more tutorial on swift, please stay tune. If any problem arises then please ask your questions via commenting, will try to respond to them as soon as possibly. Happy coding :)






No comments:

Post a Comment