【问题标题】:Add Reminder List programmatically以编程方式添加提醒列表
【发布时间】:2017-08-11 16:27:45
【问题描述】:

我正在构建一个与 macOS 提醒应用程序交互的应用程序。我正在尝试创建一个新的提醒列表,稍后我可以将提醒导入其中。

这是我目前所拥有的:

func setCalendar(_ type: EKEntityType) {

    let eventStore = EKEventStore()

    let newCalendar = EKCalendar(for: type, eventStore: eventStore)
    newCalendar.title="newcal"
    print("Cal: " + newCalendar.title)

    try? eventStore.saveCalendar(newCalendar, commit: true)

}

但是,没有创建提醒列表。

【问题讨论】:

  • 你是怎么调用这个函数的?您是否请求访问提醒?您的项目中是否正确设置了功能?
  • 您的代码会默默地忽略错误,这是一种非常糟糕的做法。如果将最后一行替换为 do {try eventStore.saveCalendar(newCalendar, commit: true);print("success")} catch {print(error)} 会得到什么?
  • 我使用 init 中的 setCalendar(.reminder) 从自定义导入器类调用该函数。我确实请求访问提醒并正确设置了所有功能 => 我确实获得了用于下拉字段的现有提醒列表。
  • 我添加了 do {} catch {} => 日历没有源...如何向它添加源?

标签: swift macos eventkit ekreminder


【解决方案1】:

问题在于您没有指定新日历的.source。如果不这样做,您将无法创建任何类型的日历(事件或提醒)。

【讨论】:

  • 谢谢,这正是缺少的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-15
  • 1970-01-01
  • 2012-06-20
  • 2020-11-09
  • 1970-01-01
相关资源
最近更新 更多