O'Reilly logo

iOS 7 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required