I had this issue as well. After some debugging I realised that I was causing the additional EKEventStoreChangedNotification
calls (for example, by creating or removing EKReminder
s). The EKEventStoreChangedNotification
eventually gets triggered when I do an estore.commit()
.
I fixed this by declaring global variable like so:
// the estore.commit in another function causes a new EKEventStoreChangedNotification. In such cases I will set the ignoreEKEventStoreChangedNotification to true so that I DON'T trigger AGAIN some of the other actions.
var ignoreEKEventStoreChangedNotification = false
And then doing this in AppDelegate.swift
where I listen to EKEventStoreChangedNotification
:
nc.addObserver(forName: NSNotification.Name(rawValue: "EKEventStoreChangedNotification"), object: estore, queue: updateQueue) {
notification in
if ignoreEKEventStoreChangedNotification {
ignoreEKEventStoreChangedNotification = false
return
}
// Rest of your code here.
}
In the function where I make changes to the estore I do this:
//
// lots of changes to estore here...
//
ignoreEKEventStoreChangedNotification = true // the estore.commit causes a new EKEventStoreChangedNotification because I made changes. Ignore this EKEventStoreChangedNotification - I know that changes happened, I caused them!
try estore.commit()
It's not pretty with the global variable (especially if you're into functional programming) but it works.