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:
EKEntityTypeEventPermission to access/add/delete/modify events in the user’s calendars.
EKEntityTypeReminderPermission to access/add/delete/modify reminders in the user’s calendars.
The method returns one of the following values:
EKAuthorizationStatusAuthorizedYour app is authorized to access the given type of items (events or reminders).
EKAuthorizationStatusDeniedThe user has previously denied your app’s access to the event store, and this remains in force.
EKAuthorizationStatusNotDeterminedYour 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 theEKEventStoreclass.EKAuthorizationStatusRestrictedDue 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*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{EKEventStore*eventStore=[[EKEventStore ...
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