在AppDelegate.m中获取屏幕上当前显示的UIViewController
UIViewController屏幕上的当前电流需要通过设置一些徽标视图来响应来自APN的推送通知。但是我怎么能获得UIViewControllerin方法application:didReceiveRemoteNotification:of AppDelegate.m? 我尝试使用self.window.rootViewController获取当前的显示UIViewController,它可能是一个UINavigationViewController或其他某种类型的视图控制器。而且我发现的visibleViewController属性UINavigationViewController可用于UIViewController在屏幕上显示。但是如果不是,该UINavigationViewController怎么办? 任何帮助表示赞赏!相关代码如下。 AppDelegate.m ... - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { //I would like to find out which view controller is on the screen here. UIViewController *vc = [(UINavigationViewController *)self.window.rootViewController visibleViewController]; [vc performSelector:@selector(handleThePushNotification:) withObject:userInfo]; } ... ViewControllerA.m - (void)handleThePushNotification:(NSDictionary *)userInfo{ //set some badge view here }