Tutorial details

Calendar Events and Permissions in iOS 6 | App Code for Sale | Preview

Calendar Events and Permissions in iOS 6 | iOS Tutorial

How to add an event to the user’s calendar at the current date

Overview PAGE TOP

Prior to iOS 6, accessing the calendar didn’t require any permission. We just had to create an event store and then we were able to add events through it.

With iOS6 the story is slightly different: to create a new event we ask the user for the permission to access his calendar.

Thanks to the new function requestAccessToEntityType:completion: that has been added to the EKEventStore, this operation is extremely simple. Let’s see how to deal with it with a simple example (you can find the source code at the end of this post).

The application I created for this post adds an event to the user’s calendar at the current date, but before doing that, it asks the user for the right permissions. Check this portion of code to understand how that function works:

1   //Request the access to the Calendar
2   [eventStore requestAccessToEntityType:EKEntityTypeEvent
3   
4    completion:^(BOOL granted,NSError* error){
5               
6               //Access not granted-------------
7               if(!granted){
8   
9               }
10              
11              //Access granted------------------
12              }else{
13  
14                          }
15   }];

Briefly, we request the permission to access a specific entity type (this case EKEventTypeEvent). The user will be warned by a system alert which asks him whether the application can access his calendar or not. Depending on the user’s answer we define two different behaviours within the completion block.

This block is executed every time we ask for this permission but the system alert is prompted to the user only once. To change his choice the user has to access device privacy settings.

Note: If you delete the application from your device, the privacy settings will not be removed and will be there even if you reinstall the application. To remove them you have to manually reset the privacy settings from General-> Reset-> Reset Location & Privacy.

Reference PAGE TOP

http://www.thinkandbuild.it/calendar-events-and-permissions-in-ios-6/

0 Comments Leave a comment

Please login in order to leave a comment.

Newest first
!

Sign-in to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.