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?
Tells the delegate that the app is about to enter the foreground.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With