I have written a code to create an event. Code is pretty straight forward :
let eventStore : EKEventStore = EKEventStore()
eventStore.requestAccess(to: .event, completion: {
granted, error in
if (granted) && (error == nil) {
print("granted \(granted)")
print("error \(String(describing: error))")
let event:EKEvent = EKEvent(eventStore: eventStore)
event.title = title
event.startDate = startDate
event.endDate = endDate
event.notes = "Lecture"
event.calendar = eventStore.defaultCalendarForNewEvents
// eventStore.saveEvent(event, span: EKSpanThisEvent, error: nil)
guard ((try? eventStore.save(event, span: EKSpan.thisEvent, commit: true)) != nil)else{
print("error saving event")
completion(false)
return
}
print("Saved Event")
}}
When the code runs first time it gives this error :
[EventKit] Error getting default calendar for new events: Error Domain=EKCADErrorDomain Code=1019 "(null)" 2018-05-18 00:18:16.586150+0500 SevimFahrschuleMobile[11413:3650672] [EventKit] No object ID provided. Will not find out if the object exists.
But when I run this code again, it works. I am not getting. There is kind of similar question here but the solution there is to get authorization for reminders and then save event, ie
eventStore.requestAccess(to: .reminder) { (<#Bool#>, <#Error?#>) in
<#code#>
}
which sounds totally illogical to me.
Let me know if you see any reason for first time failure. Thanks
Add the following in Info.plist :
NSCalendarsUsageDescription
NSRemindersUsageDescription
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.