1
votes

Prior to IOS 9 my ViewController class included NSNotificationCenter observers and the @selector() methods got called (code shown below) correctly. However starting iOS 9 the methods no longer gets called. Does anyone have the same problem ? I need to know if there are solutions to this or I need to make Delegate calls from AppDelegate class to my viewController. Thank you in advance.

Note that I had those in viewWillAppear and removeObserver in viewWillDisappear.

I have looked into apple document https://developer.apple.com/library/prerelease/mac/releasenotes/Foundation/RN-Foundation/index.html#//apple_ref/doc/uid/TP30000742 and it states that we no longer need to remove observer for weak link notification so I remove the 'removeObserver' from viewWillDisappear.

 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnteringForeground) name:UIApplicationWillEnterForegroundNotification object:nil];

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationBecameActive) name:UIApplicationDidBecomeActiveNotification object:nil];

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationResignedActive) name:UIApplicationWillResignActiveNotification object:nil];
1
Some have reported a delay might help. Something like this perhaps: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; }); - Yohst

1 Answers

3
votes

Some have reported a delay might help. Something like this perhaps: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; });