From 60ff640cf488a2000c12e448e783595041e3dc47 Mon Sep 17 00:00:00 2001 From: Rafael da Silva Ferreira <2582032-RafaelPlantard@users.noreply.gitlab.com> Date: Thu, 12 Dec 2024 09:29:44 -0300 Subject: [PATCH 1/2] refactor: Avoid creating a new EKEventStore every time that the permission is requested --- .../strategies/EventPermissionStrategy.m | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/permission_handler_apple/ios/Classes/strategies/EventPermissionStrategy.m b/permission_handler_apple/ios/Classes/strategies/EventPermissionStrategy.m index 41baccbc0..2c7ac518b 100644 --- a/permission_handler_apple/ios/Classes/strategies/EventPermissionStrategy.m +++ b/permission_handler_apple/ios/Classes/strategies/EventPermissionStrategy.m @@ -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]; } @@ -49,11 +60,9 @@ - (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 { @@ -61,7 +70,7 @@ - (void)requestPermission:(PermissionGroup)permission completionHandler:(Permiss } }]; } else if (permission == PermissionGroupCalendarWriteOnly) { - [eventStore requestWriteOnlyAccessToEventsWithCompletion:^(BOOL granted, NSError *error) { + [[EventPermissionStrategy sharedEventStore] requestWriteOnlyAccessToEventsWithCompletion:^(BOOL granted, NSError *error) { if (granted) { completionHandler(PermissionStatusGranted); } else { @@ -69,7 +78,7 @@ - (void)requestPermission:(PermissionGroup)permission completionHandler:(Permiss } }]; } else if (permission == PermissionGroupReminders) { - [eventStore requestFullAccessToRemindersWithCompletion:^(BOOL granted, NSError *error) { + [[EventPermissionStrategy sharedEventStore] requestFullAccessToRemindersWithCompletion:^(BOOL granted, NSError *error) { if (granted) { completionHandler(PermissionStatusGranted); } else { @@ -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 { From 7a1862d55076da194c60d8c3db5644c2eda7beba Mon Sep 17 00:00:00 2001 From: Rafael da Silva Ferreira <2582032-RafaelPlantard@users.noreply.gitlab.com> Date: Thu, 12 Dec 2024 09:33:20 -0300 Subject: [PATCH 2/2] chore: Bump permission_handler_apple version to 9.4.6 --- permission_handler_apple/CHANGELOG.md | 4 ++++ permission_handler_apple/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/permission_handler_apple/CHANGELOG.md b/permission_handler_apple/CHANGELOG.md index 05dd219d7..51f71e05a 100644 --- a/permission_handler_apple/CHANGELOG.md +++ b/permission_handler_apple/CHANGELOG.md @@ -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. diff --git a/permission_handler_apple/pubspec.yaml b/permission_handler_apple/pubspec.yaml index ef6679c56..c0a3fb49f 100644 --- a/permission_handler_apple/pubspec.yaml +++ b/permission_handler_apple/pubspec.yaml @@ -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"