If add an observer for a notification in the AppDelegate, do I need to bother removing it?
Asked Answered
S

1

8

In the AppDelegate's didFinishLaunchingWithOptions:

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

This is so I can merge changes to the data from other threads.

Question: Do I need to bother removing this listener in applicationWillResignActive or applicationWillTerminate? It doesn't seem like there's a point. I guess I'm asking if it's normal to have listeners like this in the main loop that never get removed.

Sphenogram answered 5/3, 2012 at 0:55 Comment(0)
G
8

You can never remove it, but if your app receive a notification (it won't happen in this case) while it is in background the notification will be queued and delivered to the application when it comes up again (if the app isn't killed ofc).

If don't want notifications that happen when your app is in background to be delivered once it comes up you can remove the listener in the methods you pointed out.

In this case, actually, it doesn't matter.

Gather answered 5/3, 2012 at 0:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.