I'm trying to hide a UIAlertView from the chat screen and shows on all other pages when the user receives a message.
Any idea how i can find the current controller from appDelegate ?
I'm a noob with objective C still learning.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (isOnInstantMessagingScreen) {
   //Show nothing
}
else {
UIApplicationState state = [application applicationState];
   if (state == UIApplicationStateActive) {
    NSString *cancelTitle = @"Close";
    NSString *showTitle = @"View";
    NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"New Message!"
                                                        message:message
                                                       delegate:self
                                              cancelButtonTitle:cancelTitle
                                              otherButtonTitles:showTitle, nil];
    [alertView show];
}
}
I have found this:
 - (UIViewController *)topViewController{
  return [self topViewController:[UIApplication     sharedApplication].keyWindow.rootViewController];
      }
     - (UIViewController *)topViewController:(UIViewController *)rootViewController
  {
  if ([rootViewController isKindOfClass:[UINavigationController class]]) {
    UINavigationController *navigationController = (UINavigationController          *)rootViewController;
   return [self topViewController:[navigationController.viewControllers     lastObject]];
}
     if ([rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tabController = (UITabBarController *)rootViewController;
return [self topViewController:tabController.selectedViewController];
}
    if (rootViewController.presentedViewController) {
return [self topViewController:rootViewController];
}
 return rootViewController;
   }
And my messages controller = MessageViewController
How can i call this code in?
 
     
    