我对 swift 很陌生,所以我只是希望有人可以帮助我 - 我正在尝试使用 UIEventKit 将事件添加到日历中(我已经想出了如何去做)但是有两件事我不确定关于:
1 - 我希望能够将事件添加到特定日期的下一个实例。例如。下一个星期一
2 - 我希望能够让该事件在当天重复发生一定次数 - 比如说 4。
任何人都可以在上述任何一个方面提供任何帮助,我们将不胜感激!
这是我到目前为止所拥有的:
func createEvent(eventStore: EKEventStore, title: String, startDate: NSDate, endDate: NSDate){
let event = EKEvent(eventStore: eventStore)
event.title = title
event.startDate = startDate
event.endDate = endDate
event.calendar = eventStore.defaultCalendarForNewEvents
do {
try eventStore.saveEvent(event, span: .ThisEvent)
}catch {
let alertView = UIAlertController(title: "Access Denied", message: "Please change your settings to allow us to access your calendar", preferredStyle: UIAlertControllerStyle.Alert)
alertView.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alertView, animated: true, completion: nil)
}
}
@IBAction func addToCalendar(sender: UIButton) {
let eventStore = EKEventStore()
let startDate = NSDate()
let endDate = startDate.dateByAddingTimeInterval(60 * 30)
if (EKEventStore.authorizationStatusForEntityType(.Event) != EKAuthorizationStatus.Authorized) {
eventStore.requestAccessToEntityType(.Event, completion: {
granted, error in
self.createEvent(eventStore, title: "Psychology Lecture", startDate: startDate, endDate: endDate)
})
}else {
createEvent(eventStore, title: "Psychology Lecture", startDate: startDate, endDate: endDate)
}
}