[英]Swift - retrieving all events from calendar and get event's participates
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
我得到的输出是:凯特·贝尔的生日凯特·贝尔的生日凯特·贝尔的生日凯特·贝尔的生日约翰·阿普尔兹的生日约翰·阿普尔兹的生日约翰·阿普尔的生日约翰·阿普尔的生日安娜·哈罗的生日安娜·哈罗的生日安娜·哈罗的生日安娜·哈罗的生日大卫·泰勒的诞辰泰勒诞辰戴维·泰勒诞辰
To fetch events from all calendars assign nil to calendars parameter of instance method predicateForEvents(withStart:end:calendars:). 要从所有日历中获取事件,请将nil分配给实例方法predicateForEvents(withStart:end:calendars :)的Calendars参数。
let predicate = store.predicateForEvents(withStart: (dates.first?.dateObject)!, end: (dates.last?.dateObject)!, calendars: nil)
https://developer.apple.com/documentation/eventkit/ekeventstore/1507479-predicateforevents https://developer.apple.com/documentation/eventkit/ekeventstore/1507479-predicateforevents
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.