【问题标题】:How to fetch my app's events from calendar?如何从日历中获取我的应用程序的事件?
【发布时间】:2018-08-07 06:21:54
【问题描述】:

我已经使用 EventKit 将事件添加到日历中,并且我可以从日历中获取所有事件,但我只需要从日历中获取我的应用程序的事件。所以现在我的问题是,如何获取与我的应用程序相关的事件。

【问题讨论】:

    标签: ios swift xcode8


    【解决方案1】:
    func getEvents() -> [EKEvent] {
        var allEvents: [EKEvent] = []
    
        // calendars
        let calendars = self.eventStore.calendars(for: .event)
    
        // iterate over all selected calendars
        for (_, calendar) in calendars.enumerated() where isCalendarSelected(calendar.calendarIdentifier) {
    
            // predicate for today (start to end)
            let predicate = self.eventStore.predicateForEvents(withStart: self.initialDates.first!, end: self.initialDates.last!, calendars: [calendar])
    
            let matchingEvents = self.eventStore.events(matching: predicate)
    
            // iterate through events
            for event in matchingEvents {
                allEvents.append(event)
            }
        }
    
        return allEvents
    }
    

    此代码将为您提供所有事件,然后您必须按标题或可以识别此事件来自您的应用的其他内容对其进行过滤:)

    【讨论】:

      猜你喜欢
      • 2017-07-14
      • 2012-02-12
      • 2013-08-12
      • 1970-01-01
      • 2016-11-20
      • 1970-01-01
      • 2011-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多