In my app (game) I'm trying to use the NSNotificationCenter to pause and resume the game when either the center/home or lock button is pressed. This is the code I'm using:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(pauseLayer:)
name:UIApplicationWillResignActiveNotification
object:self.view.layer.sublayers];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(pauseLayer:)
name:UIApplicationDidEnterBackgroundNotification
object:self.view.layer.sublayers];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(resumeLayer:)
name:UIApplicationWillEnterForegroundNotification
object:self.view.layer.sublayers];
I have experimented with putting it in lots of different places like viewDidLoad, viewDidAppear, initWithNibNameOrNil, but although they are all being called, the methods pauseLayer and resumeLayer never get called, even though the app delegate method does. Why doesn't this code work?