Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated requestAccessToEntityType leads to permission error #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions CalendarManager/CalendarManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,34 @@ - (void)eventEditViewController:(EKEventEditViewController *)controller didCompl
- (void)initEventStoreWithCalendarCapabilities:(NSDictionary *)details callback:(RCTResponseSenderBlock)callback
{
EKEventStore *localEventStore = [[EKEventStore alloc] init];
[localEventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (error) {
return callback(@[@{@"type":@"permission", @"message": error.localizedDescription}]);
}

if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
self.eventStore = localEventStore;
[self addEvent:details callback:callback];
});
} else {
NSString *errorMessage = @"User denied calendar access";
callback(@[@{@"type":@"permission", @"message":errorMessage}]);
NSLog(@"%@", errorMessage);
}
}];

if (@available(iOS 17, *)) {
[localEventStore requestWriteOnlyAccessToEventsWithCompletion:^(BOOL granted, NSError *error) {
[self handleEventStoreAccessWithGranted:granted error:error localEventStore:localEventStore details:details callback:callback];
}];
} else {
[localEventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
[self handleEventStoreAccessWithGranted:granted error:error localEventStore:localEventStore details:details callback:callback];
}];
}
}

- (void)handleEventStoreAccessWithGranted:(BOOL)granted error:(NSError *)error localEventStore:(EKEventStore *)localEventStore details:(NSDictionary *)details callback:(RCTResponseSenderBlock)callback
{
if (error) {
return callback(@[@{@"type":@"permission", @"message": error.localizedDescription}]);
}

if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
self.eventStore = localEventStore;
[self addEvent:details callback:callback];
});
} else {
NSString *errorMessage = @"User denied calendar access";
callback(@[@{@"type":@"permission", @"message":errorMessage}]);
NSLog(@"%@", errorMessage);
}
}

@end