Skip to content

Commit

Permalink
566
Browse files Browse the repository at this point in the history
  • Loading branch information
hooliapps committed Sep 27, 2023
1 parent ffb2a32 commit b7bfa12
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions src/ios/Calendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,16 @@ - (void) pluginInitialize {
}

- (void) initEventStoreWithCalendarCapabilities {
__block BOOL accessGranted = NO;
EKEventStore* eventStoreCandidate = [[EKEventStore alloc] init];
if([eventStoreCandidate respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[eventStoreCandidate 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) {
self.eventStore = eventStoreCandidate;
}
EKEventStore* eventStoreCandidate = [[EKEventStore alloc] init];

[eventStoreCandidate requestFullAccessToEventsWithCompletion:^(BOOL granted, NSError *error) {
if (granted) {
self.eventStore = eventStoreCandidate;
NSLog(@"Full access to the event store granted and eventStore initialized.");
} else {
NSLog(@"Access to the event store not granted. Error: %@", error.localizedDescription);
}
}];
}

#pragma mark Helper Functions
Expand Down Expand Up @@ -488,15 +482,6 @@ - (void) openCalendar:(CDVInvokedUrlCommand*)command {
- (void) listCalendars:(CDVInvokedUrlCommand*)command {
[self.commandDelegate runInBackground: ^{
NSArray * calendars = [self.eventStore calendarsForEntityType:EKEntityTypeEvent];

if (calendars == nil) {
CDVPluginResult* pluginResult =
[CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:
@"Calendars could not be listed. Is access to the Calendar blocked for this app?"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}

NSMutableArray *finalResults = [[NSMutableArray alloc] initWithCapacity:calendars.count];
for (EKCalendar *thisCalendar in calendars) {
NSString *type = [[NSArray arrayWithObjects:@"Local", @"CalDAV", @"Exchange", @"Subscription", @"Birthday", @"Mail", nil] objectAtIndex:thisCalendar.type];
Expand Down Expand Up @@ -1082,4 +1067,4 @@ -(CDVCommandStatus)requestCalendarAccess{
}


@end
@end

0 comments on commit b7bfa12

Please sign in to comment.