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

refactor: Avoid creating a new EKEventStore every time that the permission is requested #1417

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions permission_handler_apple/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 9.4.6

* refactor: Avoid creating a new EKEventStore every time that the permission is requested

## 9.4.5

* Fixes issue #1002, Xcode warning of the unresponsive of main thread when checking isLocationEnabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@

@implementation EventPermissionStrategy

+ (EKEventStore *)sharedEventStore {
static EKEventStore *sharedEventStore = nil;
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
sharedEventStore = [[EKEventStore alloc] init];
});

return sharedEventStore;
}

- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
return [EventPermissionStrategy permissionStatus:permission];
}
Expand Down Expand Up @@ -49,27 +60,25 @@ - (void)requestPermission:(PermissionGroup)permission completionHandler:(Permiss
#endif
}

EKEventStore *eventStore = [[EKEventStore alloc] init];

if (@available(iOS 17.0, *)) {
if (permission == PermissionGroupCalendar || permission == PermissionGroupCalendarFullAccess) {
[eventStore requestFullAccessToEventsWithCompletion:^(BOOL granted, NSError *error) {
[[EventPermissionStrategy sharedEventStore] requestFullAccessToEventsWithCompletion:^(BOOL granted, NSError *error) {
if (granted) {
completionHandler(PermissionStatusGranted);
} else {
completionHandler(PermissionStatusPermanentlyDenied);
}
}];
} else if (permission == PermissionGroupCalendarWriteOnly) {
[eventStore requestWriteOnlyAccessToEventsWithCompletion:^(BOOL granted, NSError *error) {
[[EventPermissionStrategy sharedEventStore] requestWriteOnlyAccessToEventsWithCompletion:^(BOOL granted, NSError *error) {
if (granted) {
completionHandler(PermissionStatusGranted);
} else {
completionHandler(PermissionStatusPermanentlyDenied);
}
}];
} else if (permission == PermissionGroupReminders) {
[eventStore requestFullAccessToRemindersWithCompletion:^(BOOL granted, NSError *error) {
[[EventPermissionStrategy sharedEventStore] requestFullAccessToRemindersWithCompletion:^(BOOL granted, NSError *error) {
if (granted) {
completionHandler(PermissionStatusGranted);
} else {
Expand All @@ -80,7 +89,7 @@ - (void)requestPermission:(PermissionGroup)permission completionHandler:(Permiss
} else {
EKEntityType entityType = [EventPermissionStrategy getEntityType:permission];

[eventStore requestAccessToEntityType:entityType completion:^(BOOL granted, NSError *error) {
[[EventPermissionStrategy sharedEventStore] requestAccessToEntityType:entityType completion:^(BOOL granted, NSError *error) {
if (granted) {
completionHandler(PermissionStatusGranted);
} else {
Expand Down
2 changes: 1 addition & 1 deletion permission_handler_apple/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: permission_handler_apple
description: Permission plugin for Flutter. This plugin provides the iOS API to request and check permissions.
repository: https://github.com/baseflow/flutter-permission-handler
issue_tracker: https://github.com/Baseflow/flutter-permission-handler/issues
version: 9.4.5
version: 9.4.6

environment:
sdk: ">=2.15.0 <4.0.0"
Expand Down
Loading