Chapter 19. Calendar

The user’s calendar information, which the user sees through the Calendar app, is effectively a database of calendar events. Since iOS 6, the calendar database has also included 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 EKEventStore early on, maintaining that instance in an instance variable until you no longer need it (similar to what I did with the address book database in Chapter 18). In the examples in this chapter, my EKEventStore instance is called self.database throughout.

An attempt to work with the calendar database will fail unless the user has granted your app access to it. You should start by calling the class method authorizationStatusForEntityType: with either EKEntityTypeEvent (to work with calendar events) or EKEntityTypeReminder (to work with reminders). If the returned EKAuthorizationStatus is EKAuthorizationStatusNotDetermined, you can call requestAccessToEntityType:completion:, with a non-nil completion block taking a BOOL and an NSError; this causes a system alert to appear, prompting ...

Get Programming iOS 7, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.