我正在尝试在macOS 10.14上使用Swift 4创建日历事件
我请求访问:
self.eventStore.requestAccess(to: .event, completion: { (granted, error) in
print(granted)
})
然后,我尝试使用以下方法创建事件:
let event = EKEvent(eventStore: self.eventStore)
event.title = "Help me SO"
event.startDate = Date()
event.endDate = Calendar.current.date(byAdding: .hour, value: 1, to: Date())
event.calendar = self.eventStore.defaultCalendarForNewEvents
do {
try eventStore.save(event, span: .thisEvent, commit: true)
} catch let error as NSError { //This is never called
print("failed to save event with error : \(error)")
}
print("Saved Event") //This prints
现在,当我这样做时,我会观察到一些奇怪的行为。
新创建的事件不会显示在内置macOS日历中。但是,它确实显示在内置的iOS日历上,暗示事件正在创建和存储中,只是没有显示。
谢谢!