我正在尝试将事件添加到Apple日历中 以下是我的代码
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "E, d MMM yyyy h:mm a"
let date = dateFormatter.date(from: dateE)
let event:EKEvent = EKEvent(eventStore: appleEventStore)
event.title = title!
event.startDate = date!
event.endDate = date!
event.notes = text
let alarm = EKAlarm(relativeOffset: -3600)
event.addAlarm(alarm)
let location = EKStructuredLocation(title: address!)
location.radius = 1000.0
location.geoLocation = CLLocation(latitude:(location?.latitude)!, longitude:(.location.longitude)!)
event.structuredLocation = location
event.calendar = appleEventStore.defaultCalendarForNewEvents
do {
try appleEventStore.save(event, span: .thisEvent)
}
catch let e as NSError {
let message = "Failed to add event to Calender ::" + e.description
}
我在屏幕截图中显示错误,事件未添加到日历
请任何人知道这个问题
答案 0 :(得分:0)
如果为事件设置了EKStructuredLocation,并且默认日历(defaultCalendarForNewEvents)是Exchange类型,则我收到此异常。
检查日历类型并设置EKEvent参数解决了我的问题