Chapter 19. Calendar
The user’s calendar information, which the user sees through the Calendar app, is effectively a database of calendar events. The calendar database also includes reminders, which the user sees through the Reminders app. This database can be accessed directly through the Event Kit framework. You’ll need to import EventKit.
A user interface for interacting with the calendar is also provided, through the Event Kit UI framework. You’ll need to import EventKitUI.
Calendar Database
The calendar database is accessed as an instance of the EKEventStore class. This instance is expensive to obtain but lightweight to maintain, so your usual strategy will be to instantiate and retain one EKEventStore instance. There is no harm in initializing a property as an EKEventStore instance and keeping that reference for the rest of the app’s lifetime:
let database = EKEventStore()
In the examples in this chapter, my EKEventStore instance is called self.database throughout.
Calendar Database Authorization
Although there is one database, access to calendar events and access to reminders are considered two separate forms of access and require separate authorizations. To learn authorization status, call the EKEventStore class method authorizationStatusForEntityType: with an EKEntityType, either .Event (for access to calendar events) or .Reminder (for access to reminders). To request authorization if the status is .NotDetermined, call the EKEventStore instance method requestAccessToEntityType:completion: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access