如何包含手机中的所有日历?
Posted
技术标签:
【中文标题】如何包含手机中的所有日历?【英文标题】:How can I include all the calendars from my phone? 【发布时间】:2017-05-25 17:32:04 【问题描述】:我制作了一个应用程序,它通过EventKit
获取所有日历事件,但我编写的代码仅适用于特定标题:
func readEvents()
let eventStore = EKEventStore()
let calendars = eventStore.calendars(for: .event)
for calendar in calendars
if calendar.title == "Work"
//let predicate = eventStore.predicateForReminders(in: [calendar])
let oneMonthAgo = NSDate(timeIntervalSinceNow: -30*24*3600)
let oneMonthAfter = NSDate(timeIntervalSinceNow: +30*24*3600)
let predicate = eventStore.predicateForEvents(withStart: oneMonthAgo as Date, end: oneMonthAfter as Date, calendars: [calendar])
var events = eventStore.events(matching: predicate)
for event in events
titles.append(event.title)
print([titles])
这仅适用于“工作”日历中的事件,我怎样才能包括所有事件而不考虑日历?
【问题讨论】:
【参考方案1】:您的所有日历都在 calendars
数组中。在迭代中,您遍历所有内容,但有一个条件是只有在日历名为 Work 时才能获取附加信息。删除if-statement
,您将获得所有日历的信息。
【讨论】:
【参考方案2】:只删除这部分?
if calendar.title == "Work"
【讨论】:
【参考方案3】:这些选项是否可以让您选择要将事件添加到哪个日历,还是添加到所有日历?
【讨论】:
以上是关于如何包含手机中的所有日历?的主要内容,如果未能解决你的问题,请参考以下文章