17

In the app I am currently developing there is interaction between the user and the users calendar, like what happens in many apps, very standard stuff. It was working fine until I upgrade to ios 6. I am now faced with the "This app does not have access to your calendars. You can enable access in Privacy Settings" dialog when I try to perform those same calendar functions yet my app does not appear on the devices calendar privacy settings. Is there some new api I need to use in order to ask the user to grant access?

Thanks a lot for helping me out with this issue whoever can help.

JLoewy
  • 535
  • 1
  • 4
  • 17

5 Answers5

28

I believe I have the exact same issue. I am deploying a normal Developer-build of the app I am working on to my iPhone 4 with iOS 6.

EDIT: I finally solved it like this, I did not find the info on the web but rather I found it in the APIs.

Run the following to request permission. This is apparently an asynchronous call and access will not be granted until the user have authorized the app.

EKEventStore *es = [[EKEventStore alloc] init];
[es requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    /* This code will run when uses has made his/her choice */
}];

Furthermore you may specify what the app is trying to do with the information in Info.plist. There is a key called Privacy - Calendars Usage Description (NSCalendarsUsageDescription) that can contain a string description that will be displayed in the prompt to the user.

Below are the full details of the problem I encountered (fixed by the above):

When I try to att an event to the calendar I see the following screen: Add Event error message

When I open settings for the calendar privacy settings, no app is visible: Settings, Privacy, Calendars

This all leads me to think that there is some setting I must put in Info.plist to enable calendar access and to ask the user for permission on start up. I have searched the web but not found anything.

@jloewy, I guess this is the same problem you are having?

www.jensolsson.se
  • 3,023
  • 2
  • 35
  • 65
9

If you plan on supporting devices prior to iOS 6, I would add the following otherwise you will get an error.

EKEventStore *store = [[EKEventStore alloc] init];    
if([store respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        /* This code will run when uses has made his/her choice */
    }];
}
Mongo
  • 2,674
  • 1
  • 20
  • 22
7

If you want to wait for the user to respond to the request, one could add some lines of code to the accepted answer:

__block BOOL accessGranted = NO;

if([store respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        accessGranted = granted;
        dispatch_semaphore_signal(sema);
    }];
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
} else { // we're on iOS 5 or older
    accessGranted = YES;
}

if (accessGranted) {
    // go on
}
tilo
  • 14,009
  • 6
  • 68
  • 85
1

It will ask for the permission only once and for the next time it remembers the choice. If you don't allow access to Calendar then it will not ask next time and will not allow adding an event to Calendar.

If you want to reset these settings, you have to delete "Privacy Settings" and then only it will ask for permissions once your app tries to access calendar using RequestAccessToEntityType API.

http://developer.apple.com/library/ios/#documentation/EventKit/Reference/EKEventStoreClassRef/Reference/Reference.html

Jeff Wolski
  • 6,332
  • 6
  • 37
  • 69
AnkitJain
  • 115
  • 5
  • Please consider adding a link to documentation. – Jeff Wolski Dec 29 '12 at 20:33
  • @Jeff - Thank you for the suggestion. Here is the link to related apple documentation: http://developer.apple.com/library/ios/#documentation/EventKit/Reference/EKEventStoreClassRef/Reference/Reference.html – AnkitJain Dec 30 '12 at 09:30
0

There is going to be a popup asking the user for permission before allowing the application to access the calendar information. If you didn't allow the application to access the calendar, you need to explicitly allow the application to access the calendar by whitelisting the application on the settings.

J2theC
  • 4,412
  • 1
  • 12
  • 14