Uiwindow+pazlabs.h (header file)
#import <UIKit/UIKit.h>@interface UIWindow (PazLabs)- (UIViewController *) visibleViewController;@end
UIWINDOW+PAZLABS.M (Implementation file)
#import "Uiwindow+pazlabs.h" @implementation uiwindow (pazlabs)- (Uiviewcontroller*) Visibleviewcontroller {Uiviewcontroller*rootviewcontroller = Self. Rootviewcontroller;return[UIWindowGetvisibleviewcontrollerfrom:rootviewcontroller];} + (Uiviewcontroller*) Getvisibleviewcontrollerfrom: (Uiviewcontroller*) VC {if([VC iskindofclass:[UinavigationcontrollerClass]]) {return[UIWindowGetvisibleviewcontrollerfrom:[((Uinavigationcontroller*) VC) Visibleviewcontroller]; }Else if([VC iskindofclass:[UitabbarcontrollerClass]]) {return[UIWindowGetvisibleviewcontrollerfrom:[((Uitabbarcontroller*) VC) Selectedviewcontroller]; }Else{if(VC. Presentedviewcontroller) {return[UIWindowGetvisibleviewcontrollerfrom:vc. Presentedviewcontroller]; }Else{returnvc } }}@end
References Link: http://stackoverflow.com/questions/11637709/ Get-the-current-displaying-uiviewcontroller-on-the-screen-in-appdelegate-m
Gets the uiviewcontroller that the current appdelegate is displaying