1
這是我簡化的事件刪除功能,它不適用於recurrenceRule。 EventStore在應用程序加載時創建一次。 使用recurrenceRule編輯和保存單個事件可以正常工作,但使用recurrenceRule刪除事件將刪除所有事件而不是一個事件,無論我通過了哪個EKSpan。同樣刪除未來事件(EKSpan.futureEvents),也會從同一個recurrenceRule中刪除以前的事件。其他一切看起來都很好。Swift 3:EKEventStore不會使用RecurrenceRule刪除單個事件
我錯過了什麼?感謝您的時間。
let eventStore = EKEventStore()
func deleteEvent(_ storedEventID: String)
{
eventStore.requestAccess(to: .event, completion: { (granted, error) in
if (granted) && (error == nil)
{
if let calendarEvent_toDelete = self.eventStore.event(withIdentifier: storedEventID){
//recurring event
if calendarEvent_toDelete.recurrenceRules?.isEmpty == false
{
let alert = UIAlertController(title: "Repeating Event", message:
"This is a repeating event.", preferredStyle: UIAlertControllerStyle.alert)
//delete this event only
let thisEvent_Action = UIAlertAction(title: "Delete this event", style: UIAlertActionStyle.default)
{
(result : UIAlertAction) -> Void in
//sometimes doesn't delete anything, sometimes deletes all reccurent events, not just current!!!
do{
try self.eventStore.remove(calendarEvent_toDelete, span: .thisEvent)
} catch let e as NSError{return}
}
alert.addAction(thisEvent_Action)
if let topViewController = UIApplication.topViewController(){
topViewController.modalPresentationStyle = UIModalPresentationStyle.overFullScreen
topViewController.present(alert, animated: true)
}
}
//not recurring event
else{
//works fine
do{
try self.eventStore.remove(calendarEvent_toDelete, span: EKSpan.thisEvent)
} catch let e as NSError{
return
}
}
}
}
})
}
發現我的問題,它不是在發佈代碼雖然。 –