Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where should i put removeObserver in AppDelegate.m, ios

My AppDelegate class is registered for a particular notification like below

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    {

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(applyThemeA:)
                                                     name:@"ThemeA"
                                                   object:nil];

    }

And applyThemeA does ( just not much )

- (void)appleThemeA:(NSNotification*)notification {
    NSLog(@"apply themeA");
}

I am placing removeObserver in applicationWillTerminate, but not so sure it is a good way for it.

Question

Is it a good place to place this method in.

I just wanna make sure I am doing the right way. If the question is not appropriate, please dont down vote.Just let me know. Thanks

like image 238
tranvutuan Avatar asked Oct 03 '12 14:10

tranvutuan


Video Answer


1 Answers

It's perfectly appropriate. Your listener is created when the app starts, so it should be destroyed when the app exits.

Technically speaking, it's not really needed though. When your application exits, everything will be destroyed, including the listener.

like image 64
Cyrille Avatar answered Sep 19 '22 20:09

Cyrille