2016-11-15 41 views
2

首先请注意,我没有多次注册为观察者,如其他各种问题中所述。带有EKEventStoreChanged通知的通知中心多次使用不同的通知调用

当我在本机日历应用程序中更改某些内容并返回到我的应用程序时,选择器会以不同的通知调用4-5次。

viewDidLoad我除去任何可能观察员和注册一次agian:

NotificationCenter.default.removeObserver(self) 
NotificationCenter.default.addObserver(self, selector: #selector(reloadModelData(notification:)), name: Notification.Name.EKEventStoreChanged, object: nil) 

的相应的方法:

此输出

“的方法称为NSConcreteNotification 0x170246300 {

@objc private func reloadModelData(notification: NSNotification) { 
    debugPrint("method called \(notification)") 
} 

信息name = EKEventStoreChangedNotification; object =; userInfo = {\ n EKEventSt oreChangedObjectIDsUserInfoKey =(\ n \“x-apple-eventkit:/// Location/p259707 \”,\ n \“x-apple-eventkit:/// Event/p264955 \”\ n); \ n}}“ “方法调用NSConcreteNotification 0x174258840 {name = EKEventStoreChangedNotification; object =; userInfo = {\ n EKEventStoreChangedObjectIDsUserInfoKey =(\ n \“x-apple-eventkit:/// Location/p259707 \”,\ n \“x-apple-eventkit:/// Event/p264955 \”\ n); \ }}“ ”方法名为NSConcreteNotification 0x17024b250 {name = EKEventStoreChangedNotification; object =; userInfo = {\ n EKEventStoreChangedObjectIDsUserInfoKey =(\ n \“x-apple-eventkit:/// Location/p259707 \”,\ n \“x-apple-eventkit:/// Event/p264955 \”\ n); \ }}“ ”方法名为NSConcreteNotification 0x174253b00 {name = EKEventStoreChangedNotification; object =; userInfo = {\ n EKEventStoreChangedObjectIDsUserInfoKey =(\ n \“x-apple-eventkit:/// Location/p259707 \”,\ n \“x-apple-eventkit:/// Event/p264955 \”\ n); \ N}}”

有谁知道如何解决这个问题。含义只有在收到此观察者的一个单一的呼叫重新进入应用程序时?

+0

请说明您有问题。当你提出建议时,你不明白你的意思。 –

+1

我编辑了相应的问题 – ph1lb4

回答

0

我想,这是它如何工作的,日历向您发送通知您所做的所有基本的变化。

The Apple's documentation建议通过调用refresh检查提醒和事件你所访问。如果返回true,就没有必要再取他们。所以多个通知到达不会造成很大的问题。

另外,我会建议订阅viewWillAppear(_:)中的通知,并取消订阅viewDidDisappear(_:)。当然也可能有例外,但通常你不想在屏幕不活动时处理它们。

+0

根据文档,重新提取所有事件和提醒也是可以的 - 这就是我将要做的事情。 即使我只是删除一个单一事件,也有4-5个电话。在我看来,这不应引发如此多的观察者行为。 – ph1lb4

+0

@ ph1lb4那有什么问题? –

+0

@ ph1lb4尝试在'viewDidDisappear'中'removeObserver'并添加'viewWillAppear'。在视图中也会出现,你将不得不检查是否有任何改变。 –