Unable to create event in iOS 7 standard calendar

#import <EventKit/EventKit.h> 

I cannot create an event in the default iOS calendar.

 EKEventStore *eventStore = [[EKEventStore alloc] init]; for (EKSource *source in eventStore.sources) { if (source.sourceType == EKSourceTypeCalDAV || source.sourceType == EKSourceTypeLocal) { NSLog(@"I found it"); break; } } 

From that moment on, he was unable to return any sources. When I create and run the application, there are no requests to provide access to the default calendar.

In general, I get an empty array:

 [eventStore.sources count] 

Even when I try to add an event without creating a new calendar (using

 [eventStore defaultCalendarForNewEvents] 
+6
source share
2 answers

I assume there is a problem accessing the EKEventStore to check the resolution, try the following,

  EKEventStore *eventStore = [[EKEventStore alloc] init]; if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]){ [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { NSLog(@"GRANTED: %c", granted); for (EKSource *source in eventStore.sources) { if (source.sourceType == EKSourceTypeCalDAV || source.sourceType == EKSourceTypeLocal) { NSLog(@"I found it"); break; } } }]; } 

Hope this helps you.

+7
source

I found a problem:

 [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { // TODO }]; 

I have to request permission manually, without permission of thought, I think it is fixed in iOS 7.0.2 build.

+2
source

Source: https://habr.com/ru/post/955240/


All Articles