From 5b1133633199a0093c010a5fafa75c3472ed2cc0 Mon Sep 17 00:00:00 2001 From: Alexis Choupault Date: Tue, 30 Jul 2024 15:22:38 +0200 Subject: [PATCH] added singleton --- ios/Classes/SwiftDeviceCalendarPlugin.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ios/Classes/SwiftDeviceCalendarPlugin.swift b/ios/Classes/SwiftDeviceCalendarPlugin.swift index f37d1a5a..96ed18ea 100644 --- a/ios/Classes/SwiftDeviceCalendarPlugin.swift +++ b/ios/Classes/SwiftDeviceCalendarPlugin.swift @@ -23,6 +23,16 @@ extension String { } } +fileprivate class SingleEventStore { + public let eventStore: EKEventStore + + public static let shared = SingleEventStore() + + private init() { + eventStore = EKEventStore() + } +} + public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin, EKEventViewDelegate, UINavigationControllerDelegate { struct DeviceCalendar: Codable { let id: String @@ -102,7 +112,7 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin, EKEventViewDele let calendarNotFoundErrorMessageFormat = "The calendar with the ID %@ could not be found" let calendarReadOnlyErrorMessageFormat = "Calendar with ID %@ is read-only" let eventNotFoundErrorMessageFormat = "The event with the ID %@ could not be found" - let eventStore = EKEventStore() + let eventStore = SingleEventStore.shared.eventStore let requestPermissionsMethod = "requestPermissions" let hasPermissionsMethod = "hasPermissions" let retrieveCalendarsMethod = "retrieveCalendars"