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 name, create events in calendar using swift this tutorial is revolving around EventKit framework which comes with Xcode. The EventKit framework provides classes for accessing and manipulating calendar events and reminders. Thus, we can add event to calendar using classes provided in EventKit framework. In this tutorial we will learn how to create event in  calendar of iPhone or device calendar in iOS apps programming using swift language.

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

Steps for creating event to device calendar

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  calendar in iOS using EventKit framework.  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