私もこの問題を抱えていました。いくつかのデバッグの後、私は追加のEKEventStoreChangedNotification
呼び出しを引き起こしていることに気付きました (たとえば、EKReminder
s を作成または削除することによって)。を実行すると、EKEventStoreChangedNotification
最終的に がトリガーされますestore.commit()
。
次のようにグローバル変数を宣言することでこれを修正しました。
// 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
そして、AppDelegate.swift
私が聞いている場所でこれを行うEKEventStoreChangedNotification
:
nc.addObserver(forName: NSNotification.Name(rawValue: "EKEventStoreChangedNotification"), object: estore, queue: updateQueue) {
notification in
if ignoreEKEventStoreChangedNotification {
ignoreEKEventStoreChangedNotification = false
return
}
// Rest of your code here.
}
estore に変更を加える関数では、次のようにします。
//
// 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()
グローバル変数ではきれいではありませんが(特に関数型プログラミングに興味がある場合)、機能します。