2

In my app I am trying to get all the events that happened during a specific time. This is the code I have:

    let store = EKEventStore()
    store.requestAccess(to: EKEntityType.event) { (granted, error) in
   if(granted){
      let calendars = store.calendars(for: EKEntityType.event)
      for calendar in calendars {
      let predicate = store.predicateForEvents(withStart: (dates.first?.dateObject)!, end: (dates.last?.dateObject)!, calendars: [calendar])

                store.enumerateEvents(matching: predicate){ (event, stop) in
                    print(event.title)

                }

            }

        }else{
        print(error)
        }

The problem with this is that it retrieve only birthdays, and dons't retrieve events created by the user or holidays in that day. Here is the output I get: Kate Bell’s Birthday Kate Bell’s Birthday Kate Bell’s Birthday Kate Bell’s Birthday John Appleseed’s Birthday John Appleseed’s Birthday John Appleseed’s Birthday John Appleseed’s Birthday Anna Haro’s Birthday Anna Haro’s Birthday Anna Haro’s Birthday Anna Haro’s Birthday David Taylor’s Birthday David Taylor’s Birthday David Taylor’s Birthday David Taylor’s Birthday

  • So how could I make it work so I could get all events including the one made by the user on its calendar.
  • And How could I retrieve the participants of each event?
Idan Aviv
  • 1,253
  • 2
  • 13
  • 23

1 Answers1

0

To fetch events from all calendars assign nil to calendars parameter of instance method predicateForEvents(withStart:end:calendars:).

let predicate = store.predicateForEvents(withStart: (dates.first?.dateObject)!, end: (dates.last?.dateObject)!, calendars: nil)

https://developer.apple.com/documentation/eventkit/ekeventstore/1507479-predicateforevents

Dare2dream
  • 76
  • 4
  • 1
    till iOS 11 this methods returning all types of events but in iOS 12, it does not returning Exchange Events such as outlook calendar events. – GvSharma Oct 01 '18 at 06:39
  • @GvSharma ...hey means if i am sending nil in IOS 12 then can't get any event from all calendar?...can you give brief that details or reference link? – Dhaval Bhadania Oct 27 '18 at 07:01