iphone - removeObserver not working for UIApplicationWillEnterForegroundNotification IOS -
hi developing iphone application in registering uiapplicationwillenterforegroundnotification notification. when tried unregister observer not working. still called. code looks
in viewdidload method registering
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(applicationbecomeactive) name:uiapplicationwillenterforegroundnotification object:nil];
and on logout method tried remove observer
[[nsnotificationcenter defaultcenter] removeobserver:uiapplicationwillenterforegroundnotification];
but not working. doing thing wrong. need help. thank you.
that's because you're not removing observer.
notice add observer method:
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(applicationbecomeactive) name:uiapplicationwillenterforegroundnotification object:nil];
the important part addobserver:self
so in order remove observer, do:
[[nsnotificationcenter defaultcenter] removeobserver:self];
or if want remove particular notification name:
[[nsnotificationcenter defaultcenter] removeobserver:self name:uiapplicationwillenterforegroundnotification object:nil];
Comments
Post a Comment