From 04d36c25629e8ea33be76135326e478e829c93dc Mon Sep 17 00:00:00 2001 From: gavira Date: Thu, 9 Jan 2025 12:19:26 +0100 Subject: [PATCH 1/4] Update SwiftDeviceCalendarPlugin.swift hasEventPermissions check ios17/18 --- ios/Classes/SwiftDeviceCalendarPlugin.swift | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ios/Classes/SwiftDeviceCalendarPlugin.swift b/ios/Classes/SwiftDeviceCalendarPlugin.swift index 323c8f5a..75040620 100644 --- a/ios/Classes/SwiftDeviceCalendarPlugin.swift +++ b/ios/Classes/SwiftDeviceCalendarPlugin.swift @@ -1104,6 +1104,7 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin, EKEventViewDele } } + /* private func hasEventPermissions() -> Bool { let status = EKEventStore.authorizationStatus(for: .event) if #available(iOS 17, *) { @@ -1112,6 +1113,36 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin, EKEventViewDele return status == EKAuthorizationStatus.authorized } } + */ + private func hasEventPermissions(completion: @escaping (Bool) -> Void) { + let eventStore = EKEventStore() + let status = EKEventStore.authorizationStatus(for: .event) + + switch status { + case .notDetermined: + // Request appropriate access based on iOS version + if #available(iOS 17, *) { + eventStore.requestFullAccessToEvents { granted, error in + completion(granted) + } + } else { + eventStore.requestAccess(to: .event) { granted, error in + completion(granted) + } + } + case .authorized: + // Prior to iOS 17 + completion(true) + case .fullAccess: + // iOS 17 and later + completion(true) + case .writeOnly, .denied, .restricted: + completion(false) + @unknown default: + completion(false) + } + } + } extension Date { From 9e3c852402595065799a7fb42c9bf261ceda0bfa Mon Sep 17 00:00:00 2001 From: gavira Date: Thu, 9 Jan 2025 12:31:03 +0100 Subject: [PATCH 2/4] Update SwiftDeviceCalendarPlugin.swift --- ios/Classes/SwiftDeviceCalendarPlugin.swift | 32 ++------------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/ios/Classes/SwiftDeviceCalendarPlugin.swift b/ios/Classes/SwiftDeviceCalendarPlugin.swift index 75040620..bacd26f0 100644 --- a/ios/Classes/SwiftDeviceCalendarPlugin.swift +++ b/ios/Classes/SwiftDeviceCalendarPlugin.swift @@ -1104,7 +1104,7 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin, EKEventViewDele } } - /* + private func hasEventPermissions() -> Bool { let status = EKEventStore.authorizationStatus(for: .event) if #available(iOS 17, *) { @@ -1113,35 +1113,7 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin, EKEventViewDele return status == EKAuthorizationStatus.authorized } } - */ - private func hasEventPermissions(completion: @escaping (Bool) -> Void) { - let eventStore = EKEventStore() - let status = EKEventStore.authorizationStatus(for: .event) - - switch status { - case .notDetermined: - // Request appropriate access based on iOS version - if #available(iOS 17, *) { - eventStore.requestFullAccessToEvents { granted, error in - completion(granted) - } - } else { - eventStore.requestAccess(to: .event) { granted, error in - completion(granted) - } - } - case .authorized: - // Prior to iOS 17 - completion(true) - case .fullAccess: - // iOS 17 and later - completion(true) - case .writeOnly, .denied, .restricted: - completion(false) - @unknown default: - completion(false) - } - } + } From bc84748fa7999e669a2620c6db166c6740470821 Mon Sep 17 00:00:00 2001 From: gavira Date: Thu, 9 Jan 2025 12:37:51 +0100 Subject: [PATCH 3/4] Update SwiftDeviceCalendarPlugin.swift EventStoreManager.shared.eventStore --- ios/Classes/SwiftDeviceCalendarPlugin.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ios/Classes/SwiftDeviceCalendarPlugin.swift b/ios/Classes/SwiftDeviceCalendarPlugin.swift index bacd26f0..9a6c239f 100644 --- a/ios/Classes/SwiftDeviceCalendarPlugin.swift +++ b/ios/Classes/SwiftDeviceCalendarPlugin.swift @@ -4,6 +4,14 @@ import Flutter import Foundation import UIKit +class EventStoreManager: ObservableObject { + static let shared = EventStoreManager() + let eventStore: EKEventStore + private init() { + eventStore = EKEventStore() + } +} + extension Date { var millisecondsSinceEpoch: Double { return self.timeIntervalSince1970 * 1000.0 } } @@ -102,7 +110,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 = EventStoreManager.shared.eventStore let requestPermissionsMethod = "requestPermissions" let hasPermissionsMethod = "hasPermissions" let retrieveCalendarsMethod = "retrieveCalendars" From 2f9f275ccd216708df2324e4259d3365dd029c8a Mon Sep 17 00:00:00 2001 From: gavira Date: Thu, 9 Jan 2025 12:45:37 +0100 Subject: [PATCH 4/4] Update SwiftDeviceCalendarPlugin.swift --- ios/Classes/SwiftDeviceCalendarPlugin.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ios/Classes/SwiftDeviceCalendarPlugin.swift b/ios/Classes/SwiftDeviceCalendarPlugin.swift index 9a6c239f..b27bc867 100644 --- a/ios/Classes/SwiftDeviceCalendarPlugin.swift +++ b/ios/Classes/SwiftDeviceCalendarPlugin.swift @@ -1112,7 +1112,6 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin, EKEventViewDele } } - private func hasEventPermissions() -> Bool { let status = EKEventStore.authorizationStatus(for: .event) if #available(iOS 17, *) { @@ -1121,8 +1120,6 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin, EKEventViewDele return status == EKAuthorizationStatus.authorized } } - - } extension Date { @@ -1180,3 +1177,4 @@ extension UIColor { } } +