我们如何使用EKEventStoreChanged从i日历中获取已删除的项目?

时间:2018-09-25 06:25:49

标签: ios swift icalendar ekevent

我正在使用以下代码处理icalendar中的更新事件:

func eventStoreChanged(_ notification: Notification) {

    let ekEventStore = notification.object as! EKEventStore

    let eDate = Utility.HelperFuntions.convertDateStringToDate("2099-12-30-00:00:00")
    let sDate = Utility.HelperFuntions.convertDateStringToDate("2018-08-01-00:00:00")

    let predicate = ekEventStore.predicateForEvents(withStart: sDate, end: eDate, calendars: [yourEventCalendar!])

    let ekEvents = ekEventStore.events(matching: predicate) 

    if let lastModifiedDate = UserDefaults.standard.value(forKey: "LastModifiedDate") as? String {

        let last_modify_date = Utility.HelperFuntions.convertDateStringToDate(lastModifiedDate)

        let events = ekEvents.filter({
            //End Time of an appointment less than Start Time
            $0.lastModifiedDate!.compare(last_modify_date) == .orderedDescending

        })

        var title = ""
        for singleEvent in events {
            title = "\(title), \(singleEvent.title)"
            print("New = \(singleEvent.isNew), Title = \(singleEvent.title), hasChanges =\(singleEvent.hasChanges)")
        }

        Utility.HelperFuntions.setuserDefault(Date().stringFromDate(Date(), format: "YYYY-MM-dd-HH:mm:ss"), key: "LastModifiedDate")
        Utility.HelperFuntions.showAlert("Title", withMessage: title)
    }
}

但是我无法删除事件。 答案将不胜感激。

0 个答案:

没有答案