Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

applicationDidBecomeActive in UIViewController?

The applicationDidBecomeActive method gets called when the app became active, is there a way that I can do this method for a certain UIViewController? I know there is viewDidAppear for view controllers but I'm searching for a method that is called when the app becomes active again AND is on a certain UIViewController. How can I achieve this?

like image 732
Shinonuma Avatar asked Jun 16 '13 11:06

Shinonuma


People also ask

When Applicationwillenterforeground is called?

Tells the delegate that the app is about to enter the foreground.

What is UIApplication in Swift?

Swift version: 5.6. Subclassing UIApplication allows you to override functionality such as opening URLs or changing your icon, but it's a non-trivial task in Swift because of the @UIApplicationMain attribute. If you look in your AppDelegate.

Which of the following method is called after UIViewController is initialized?

First UIViewController is alloc'ed by some other object, then init is immediately called (or some other init method, like initWithStyle). Only once the object is initialized would I expect it to call its own loadView function, after which the view, once loaded, calls the viewDidLoad delegate method.


1 Answers

You can listen to UIApplicationDidBecomeActiveNotification notification:

@implementation CertainViewController

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [[NSNotificationCenter defaultCenter]
   addObserver:self
   selector:@selector(applicationDidBecomeActiveNotification:)
   name:UIApplicationDidBecomeActiveNotification
   object:[UIApplication sharedApplication]];
}

- (void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];
  [[NSNotificationCenter defaultCenter]
   removeObserver:self
   name:UIApplicationDidBecomeActiveNotification
   object:[UIApplication sharedApplication]];
}

- (void)applicationDidBecomeActiveNotification:(NSNotification *)notification {
  // Do something here
}

@end
like image 80
yonosoytu Avatar answered Oct 25 '22 08:10

yonosoytu