EKEventStore *eventStore = [[UpdateManager sharedUpdateManager] eventStore];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (granted)...
I want to ask the user for permission to add an event to his calendar. After it's granted do I need to ask for permission again when I want for example to remove an event (in another session after the app was closed and reopened) or is it just a want time thing?
If it's a one time thing, can I just put it in ViewDidLoad at first lunch just to "get rid of it" ?
You only need to call it once:
BOOL needsToRequestAccessToEventStore = NO; // iOS 5 behavior
EKAuthorizationStatus authorizationStatus = EKAuthorizationStatusAuthorized; // iOS 5 behavior
if ([[EKEventStore class] respondsToSelector:@selector(authorizationStatusForEntityType:)]) {
authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
needsToRequestAccessToEventStore = (authorizationStatus == EKAuthorizationStatusNotDetermined);
}
if (needsToRequestAccessToEventStore) {
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
// You can use the event store now
});
}
}];
} else if (authorizationStatus == EKAuthorizationStatusAuthorized) {
// You can use the event store now
} else {
// Access denied
}
You shouldn't do that on the first launch, though. Only request access when you need it and that isn't the case just until the user decides to add an event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With