我想获取日历活动的与会者列表,我不知道如何在Swift 3
中执行此操作。我还希望获得任何活动参与者的电子邮件地址,以通过我的应用与他们联系。
有没有人可以帮助我?
感谢。
我用这个功能检索事件:
func loadEvents() {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
let date = Date()
let calendar2 = Calendar.current
let components = calendar2.dateComponents([.year, .month, .day], from: date)
let year = components.year
let month = components.month
let day = components.day
let startDate = dateFormatter.date(from: "\(day ?? 01)" + "-" + "\(month ?? 01)" + "-" + "\(year ?? 2017)")
let endDate = dateFormatter.date(from: "31-12-" + "\(year ?? 2099)")
if let startDate = startDate, let endDate = endDate {
let eventStore = EKEventStore()
let eventsPredicate = eventStore.predicateForEvents(withStart: startDate, end: endDate, calendars: [calendar])
self.events = eventStore.events(matching: eventsPredicate).sorted() {
(e1: EKEvent, e2: EKEvent) -> Bool in
return e1.startDate.compare(e2.startDate) == ComparisonResult.orderedAscending
}
}
}
我将它们列在UITableView
中,如下所示:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "basicCell")!
cell.textLabel?.text = events?[(indexPath as NSIndexPath).row].title
cell.detailTextLabel?.text = formatDate(events?[(indexPath as NSIndexPath).row].startDate)
return cell
}
但是,当我试图让与会者参加这样的活动时:
if (events?[(indexPath as IndexPath).row].hasAttendees)! {
let eventsAttendees: [EKParticipant]! = events?[(indexPath as IndexPath).row].attendees
}
我总是eventsAttendees = nil
我不明白。
答案 0 :(得分:0)
我得到了这样的活动与会者的姓名和电子邮件:
for attendee in event.attendees {
let email = (attendee.url.absoluteString).replacingOccurrences(of: "mailto:", with: "")
let name = attendee.name ?? ""
}