With UIalertview we can show the alert from any class and it'll always show above the current view controller
I'm using below code snippet to find out the current view controller and show the alertviewcontroller on top of that.
UITabBarController* tabBarController = (UITabBarController*) [[[AppDelegate sharedInstance]window] rootViewController];
id obj= [[[AppDelegate sharedInstance]window]rootViewController];
if([obj isMemberOfClass:[UITabBarController class]]){
UINavigationController *navController = [tabBarController selectedViewController];
UIViewController *vuContollerObj = [navController topViewController];
dispatch_async(dispatch_get_main_queue(), ^ {
[vuContollerObj presentViewController:alert animated:YES completion:nil];
});
}
else if([obj isMemberOfClass:[CommonNavigationController class]] || [obj isMemberOfClass:[UINavigationController class]]){
UINavigationController *navObj= obj;
UIViewController *vuContollerObj = [navObj topViewController];
dispatch_async(dispatch_get_main_queue(), ^ {
[vuContollerObj presentViewController:alert animated:YES completion:nil];
});
}
else{
dispatch_async(dispatch_get_main_queue(), ^ {
[obj presentViewController:alert animated:YES completion:nil];
});
}
Problem 1:
App delegate
When I try to show an alert message , It gets hidden because of upcoming view controller and it appears for very shorttime.
Problem 2:
Pushing a new viewcontroller from existing viewcontroller
when I try to show a message in view did load of a new viewcontroller... my method detects the old viewcontroller as current viewcontroller.
Any help in fixin this would be appreciated.