iOS - Event Kit编程收听通知

时间:2012-09-07 18:50:53

标签: ios cocoa-touch eventkit

我想观察日历应用程序的更改,因此我注册了EKEventStoreChangedNotification通知。但是,我是否需要让EKEventStore对象“活着”才能收到此通知?我在想我正在视图控制器上初始化EKEventStore对象以检索一些事件。然后我将弹出导航堆栈的这个视图控制器,视图控制器将被释放,因此EKEventStore对象将被释放。

2 个答案:

答案 0 :(得分:2)

不,您不需要保持EKEventStore对象处于活动状态,因为您已使用名为 eventStore

的EKEventStore对象注册EKEventStoreChangedNotification
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(storeChanged:)
                              name:EKEventStoreChangedNotification  object:eventStore];

请参阅this以获得更多疑问

答案 1 :(得分:0)

对于swift 3.x,请使用如下

NotificationCenter.default.addObserver(self, selector: #selector(ViewController.storeChanged(_:)), name: NSNotification.Name.EKEventStoreChanged, object: eventStore)
...
...
...
//Method
func storeChanged(_ nsNotification: NSNotification) {
//do your stuff
}