我正在使用下面的代码,但是每当我尝试在EKEventStore中添加事件时,都会引发此错误“未设置日历”
func createEvent(with title: String, isAllDay: Bool, notes: String? = "", location: String? = "") {
store.requestAccess(to: .event) { (granted, error) in
if error != nil {
print(error?.localizedDescription ?? "error occured")
return
}
self.store = EKEventStore()
let event = EKEvent(eventStore: self.store)
event.title = title
event.startDate = self.selectedStartDate
event.endDate = self.selectedEndDate
event.isAllDay = isAllDay
event.notes = notes
event.location = location
do {
try self.store.save(event, span: .thisEvent, commit: true)
print(event.eventIdentifier) //save event id to access this particular event later
} catch let errorThis {
print("cant add event with this error -> \(errorThis.localizedDescription)")
}
}
}