我试图在https://www.andrewcbancroft.com/2015/06/17/creating-calendars-with-event-kit-and-swift/中实现相同的代码,但我收到一条错误,指出“json错误:发生意外错误。”我正在为macOS开发这个项目。
这是我的以下代码,
@IBAction func addPressed(_ sender: NSButton) {
// Create an Event Store instance
let eventStore = EKEventStore();
// Use Event Store to create a new calendar instance
// Configure its title
let newCalendar = EKCalendar(for: .event, eventStore: eventStore)
// Probably want to prevent someone from saving a calendar
// if they don't type in a name...
newCalendar.title = "DCU"
// Access list of available sources from the Event Store
let sourcesInEventStore = eventStore.sources
// Filter the available sources and select the "Local" source to assign to the new calendar's
// source property
newCalendar.source = sourcesInEventStore.filter{
(source: EKSource) -> Bool in
source.sourceType.rawValue == EKSourceType.local.rawValue
}.first!
// Save the calendar using the Event Store instance
do {
try eventStore.saveCalendar(newCalendar, commit: true)
} catch {
print("json error: \(error.localizedDescription)")
}
}
当我构建项目并单击运行时,它给出了错误“json error:发生意外错误。”。当我尝试向defaultcalendar添加一个事件时,它给我一个错误“json错误:没有设置日历”。我已经在线尝试了所有可用的资源,但找不到解决方案。不知何故,eventStore.save或eventStore.saveCalendar都不适用于我。有人可以告诉我哪里可能出错?
两个可能的原因
com.apple.security.personal-information.calendars
权利。要了解有关App Sandbox相关权利的更多信息,请参阅Enabling App Sandbox。您的错误消息具有误导性,该错误与JSON无关。