iOS – Event Kit programming listen to notifications

流过昼夜 提交于 2019-12-21 21:25:23

问题


I want to observe changes to the Calendar application so I register for the EKEventStoreChangedNotification notification. But do I need to have an EKEventStore object "alive" for me to receive this notification? I'm thinking I'm initializing the EKEventStore object in on view controller to retrieve some events. And then I will pop this view controller of the navigation stack and the view controller will be deallocated thus the EKEventStore object will be deallocated.


回答1:


No, you don't need to keep the EKEventStore object alive as you are already registering EKEventStoreChangedNotification using EKEventStore object named eventStore

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(storeChanged:)
                              name:EKEventStoreChangedNotification  object:eventStore];

Refer this for more clearance of your doubt




回答2:


For swift 3.x, use like below

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


来源:https://stackoverflow.com/questions/12323796/ios-event-kit-programming-listen-to-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!