EKEventStore+Extensions.swift 851 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // EKEventStore+Extensions.swift
  3. // LoopFollow
  4. //
  5. // Created by Jonas Björkert on 2023-07-27.
  6. // Copyright © 2023 Jon Fawcett. All rights reserved.
  7. //
  8. import Foundation
  9. import EventKit
  10. #if swift(>=5.9)
  11. extension EKEventStore {
  12. func requestCalendarAccess(completion: @escaping (Bool, Error?) -> Void) {
  13. if #available(iOS 17, *) {
  14. requestFullAccessToEvents { (granted, error) in
  15. completion(granted, error)
  16. }
  17. } else {
  18. requestAccess(to: .event) { (granted, error) in
  19. completion(granted, error)
  20. }
  21. }
  22. }
  23. }
  24. #else
  25. extension EKEventStore {
  26. func requestCalendarAccess(completion: @escaping (Bool, Error?) -> Void) {
  27. requestAccess(to: .event) { (granted, error) in
  28. completion(granted, error)
  29. }
  30. }
  31. }
  32. #endif