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/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 { 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"