[英]If add an observer for a notification in the AppDelegate, do I need to bother removing it?
在AppDelegate的didFinishLaunchingWithOptions
:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(contextChanged:)
name:NSManagedObjectContextDidSaveNotification
object:nil];
這樣我就可以將更改合並到其他線程的數據中。
問題:我是否需要在applicationWillResignActive
或applicationWillTerminate
刪除此偵聽applicationWillTerminate
? 看起來似乎沒有意義。 我想我問的是,在主循環中有這樣的監聽器是否正常,從來沒有被刪除過。
你永遠不能刪除它,但如果你的應用程序在后台收到通知(在這種情況下不會發生),通知將排隊並在應用程序再次啟動時傳遞給應用程序(如果應用程序不是殺死了c)。
如果不希望在應用程序處於后台運行時發生的通知一旦出現就可以通過您指出的方法刪除偵聽器。
在這種情況下,實際上,沒關系。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.