1

I've searched StackOverflow and Google but nothing helped me so far. Why is the following code not working for me? Notting appears in the console. The NSLog in viewDidLoad does appear in the console...

In ViewController.m

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    NSLog(@"applicationDidEnterBackground");
}

The project is veru straight forward, one storyboard, one viewcontroller, iPad only.

Mathijs
  • 1,258
  • 1
  • 10
  • 27
  • possible duplicate of [UIViewController visible callback](http://stackoverflow.com/questions/12266909/uiviewcontroller-visible-callback) – rmaddy Mar 10 '13 at 19:30

1 Answers1

2

Only the application delegate gets that method called, not view controllers. The object should conform to the UIApplicationDelegate and needs to be set as the delegate. You set it in your MainMenu.xib. The File's Owner object in that xib is the application itself; create another object of your application delegate's class and connect the application's delegate outlet.

Any object can be apprised of application events, however, by registering with the default notification center -- the application object will both send this message to its delegate and post a notification. In this case, you want to register for UIApplicationDidEnterBackgroundNotification.

jscs
  • 63,694
  • 13
  • 151
  • 195
  • 1
    You should mention that any other class can get notified by registering for the `UIApplicationDidEnterBackgroundNotification` notification. – rmaddy Mar 10 '13 at 19:31
  • Thanks! Josh for making it clear to me, rmaddy for the solution – Mathijs Mar 10 '13 at 19:59