2012-09-07 78 views
2

我想觀察日曆應用程序的更改,因此我註冊了EKEventStoreChangedNotification通知。但是,我是否需要讓一個EKEventStore對象「活着」才能收到此通知?我想我正在初始化視圖控制器中的EKEventStore對象以檢索一些事件。然後我將彈出導航堆棧的這個視圖控制器,視圖控制器將被釋放,因此EKEventStore對象將被釋放。iOS - Event Kit編程監聽通知

+0

[@Peter Warbo](http://stackoverflow.com/users rs/294661/peter-warbo)是你的疑問清除..? –

回答

2

不,你不需要保持EKEventStore對象活着,你正在使用名爲eventStore

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

參考this您的疑問

0

的多個間隙對於EKEventStore對象EKEventStoreChangedNotification已註冊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 
}