19.1. Requesting Permission to Access Calendars

Problem

You want to add events or make other changes to the user’s calendar, but this requires the user to give your app permission.

Solution

Invoke the authorizationStatusForEntityType: class method of the EKEventStore class and pass one of the following values to it as its parameter:

EKEntityTypeEvent

Permission to access/add/delete/modify events in the user’s calendars.

EKEntityTypeReminder

Permission to access/add/delete/modify reminders in the user’s calendars.

The method returns one of the following values:

EKAuthorizationStatusAuthorized

Your app is authorized to access the given type of items (events or reminders).

EKAuthorizationStatusDenied

The user has previously denied your app’s access to the event store, and this remains in force.

EKAuthorizationStatusNotDetermined

Your app has not attempted to access the event store before, so the user has not been asked to grant or reject permission. In this case, you need to ask for permission from the user to access the event store on her device using the requestAccessToEntityType:completion: instance method of the EKEventStore class.

EKAuthorizationStatusRestricted

Due to some other restrictions on the device, such as parental controls, your app cannot access the event store on the device.

Here is a code snippet that will handle all these cases for us:

- (BOOL)            application:(UIApplication *)application
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

    EKEventStore *eventStore = [[EKEventStore ...

Get iOS 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.