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 with iOS SDK. 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.
If you are, looking for objective C version then please visit Add event to device calendar – Objective C
Steps for creating event to iPhone device calendar app
1: Add EventKit framework under Linked Frameworks and libraries
2: Create Event store object
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.
4: Create a function having three parameter’s
i) Event Title – This is the title of the event we want to show in device calendar.
ii) Event Start date – This is the event start date.
iii) Event end date – This is the event end date.
Inside the function, first step is to request user to give us permissions for accessing iphone or ipad device native calendar app. On successful access to device calendar app, we will use EKEvent class to create and add event on device calendar and finally will use EKAlarm class to set an alarm or reminder for the created 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 🙂
Pingback: Swift crear evento y agregarlo a un calendario – Adr-Avatar