EKEventStore+Extensions.swift 812 B

123456789101112131415161718192021222324252627282930
  1. // LoopFollow
  2. // EKEventStore+Extensions.swift
  3. import EventKit
  4. import Foundation
  5. #if swift(>=5.9)
  6. extension EKEventStore {
  7. func requestCalendarAccess(completion: @escaping (Bool, Error?) -> Void) {
  8. if #available(iOS 17, *) {
  9. requestFullAccessToEvents { granted, error in
  10. completion(granted, error)
  11. }
  12. } else {
  13. requestAccess(to: .event) { granted, error in
  14. completion(granted, error)
  15. }
  16. }
  17. }
  18. }
  19. #else
  20. extension EKEventStore {
  21. func requestCalendarAccess(completion: @escaping (Bool, Error?) -> Void) {
  22. requestAccess(to: .event) { granted, error in
  23. completion(granted, error)
  24. }
  25. }
  26. }
  27. #endif