@@ -16,22 +16,16 @@ - (void) pluginInitialize {
1616}
1717
1818- (void ) initEventStoreWithCalendarCapabilities {
19- __block BOOL accessGranted = NO ;
20- EKEventStore* eventStoreCandidate = [[EKEventStore alloc ] init ];
21- if ([eventStoreCandidate respondsToSelector: @selector (requestAccessToEntityType:completion: )]) {
22- dispatch_semaphore_t sema = dispatch_semaphore_create (0 );
23- [eventStoreCandidate requestAccessToEntityType: EKEntityTypeEvent completion: ^(BOOL granted, NSError *error) {
24- accessGranted = granted;
25- dispatch_semaphore_signal (sema);
26- }];
27- dispatch_semaphore_wait (sema, DISPATCH_TIME_FOREVER);
28- } else { // we're on iOS 5 or older
29- accessGranted = YES ;
30- }
31-
32- if (accessGranted) {
33- self.eventStore = eventStoreCandidate;
34- }
19+ EKEventStore* eventStoreCandidate = [[EKEventStore alloc ] init ];
20+
21+ [eventStoreCandidate requestFullAccessToEventsWithCompletion: ^(BOOL granted, NSError *error) {
22+ if (granted) {
23+ self.eventStore = eventStoreCandidate;
24+ NSLog (@" Full access to the event store granted and eventStore initialized." );
25+ } else {
26+ NSLog (@" Access to the event store not granted. Error: %@ " , error.localizedDescription );
27+ }
28+ }];
3529}
3630
3731#pragma mark Helper Functions
@@ -488,15 +482,6 @@ - (void) openCalendar:(CDVInvokedUrlCommand*)command {
488482- (void ) listCalendars : (CDVInvokedUrlCommand*)command {
489483 [self .commandDelegate runInBackground: ^{
490484 NSArray * calendars = [self .eventStore calendarsForEntityType: EKEntityTypeEvent];
491-
492- if (calendars == nil ) {
493- CDVPluginResult* pluginResult =
494- [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:
495- @" Calendars could not be listed. Is access to the Calendar blocked for this app?" ];
496- [self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
497- return ;
498- }
499-
500485 NSMutableArray *finalResults = [[NSMutableArray alloc ] initWithCapacity: calendars.count];
501486 for (EKCalendar *thisCalendar in calendars) {
502487 NSString *type = [[NSArray arrayWithObjects: @" Local" , @" CalDAV" , @" Exchange" , @" Subscription" , @" Birthday" , @" Mail" , nil ] objectAtIndex: thisCalendar.type];
@@ -1082,4 +1067,4 @@ -(CDVCommandStatus)requestCalendarAccess{
10821067}
10831068
10841069
1085- @end
1070+ @end
0 commit comments