I am building a fast application. I have several viewControllers. When someone is in a specific viewController and click the home button, I want to reject this ViewController. I do not want any actions in other view controllers. I found out when I press the home button after the Appdelagate function calls
func applicationDidEnterBackground(application: UIApplication) {
print("Enter my Guess")
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
Therefore, I managed to capture this action using Notifier on my view controller (viewDidLoad), as shown below.
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("myObserverMethod:"), name:UIApplicationDidEnterBackgroundNotification, object: nil)
AND
func myObserverMethod(notification : NSNotification) {
if let viewControllers = navigationController?.viewControllers {
for viewController in viewControllers {
if viewController.isKindOfClass(HomeVC) {
print("I am calledr")
}
}
}
}
Now my View Control problem is not firing. I mean that no action will happen. How to handle this.
Note. . When I press the "home" button, the called function is myObserverMethod and is called ("I am also called").
?
1:
, HomeVC ( ), .
2:
, , .. . , HomeVC . , . :
if (viewController.isViewLoaded() && viewController.view.window != nil){
print("I am calledr")
viewController.dismissViewControllerAnimated(false, completion: nil)
// self.presentingViewController!.dismissViewControllerAnimated(false, completion: nil)
// viewController.dismissViewControllerAnimated(false, completion: nil)
}
. , .