If I add an observer for notification in AppDelegate, do I need to delete it?

In AppDelegate didFinishLaunchingWithOptions :

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextChanged:) name:NSManagedObjectContextDidSaveNotification object:nil]; 

This means that I can merge changes into data from other streams.

Question: Do I need to worry about deleting this listener in applicationWillResignActive or applicationWillTerminate ? There seems to be no point. I’m probably asking if it’s normal to have listeners in the main loop that are never deleted.

+6
source share
1 answer

You can never delete it, but if your application receives a notification (this will not happen in this case) when it is in the background, the notification will be queued and delivered to the application when it appears again (if the application is not killed c) .

If you do not want notifications that occur when your application is in the background, which will be delivered after it appears, you can remove the listener in the methods that you specified.

In this case, in fact, it does not matter.

+7
source

Source: https://habr.com/ru/post/909962/


All Articles