我有兴趣知道如何在设备中添加日历事件,但使用swift。我知道在Objective-C中有一些例子,但目前还没有什么是迅速的。非常感谢。
Swift 3.0版本
原文链接:https://www.f2er.com/swift/320363.htmllet eventStore : EKEventStore = EKEventStore() // 'EKEntityTypeReminder' or 'EKEntityTypeEvent' eventStore.requestAccess(to: .event) { (granted,error) in if (granted) && (error == nil) { print("granted \(granted)") print("error \(error)") let event:EKEvent = EKEvent(eventStore: eventStore) event.title = "Test Title" event.startDate = Date() event.endDate = Date() event.notes = "This is a note" event.calendar = eventStore.defaultCalendarForNewEvents do { try eventStore.save(event,span: .thisEvent) } catch let error as NSError { print("Failed to save event with error : \(error)") } print("Saved Event") } else{ print("Failed to save event with error : \(error) or access not granted") } }
参考:https://gist.github.com/mchirico/d072c4e38bda61040f91