相关疑难解决方法(0)

在AppDelegate.m的屏幕上获取当前显示的UIViewController

UIViewController屏幕上的当前需要通过设置徽标视图来响应来自APN的推送通知.但我怎么能得到UIViewControllerin方法application:didReceiveRemoteNotification:AppDelegate.m

我尝试使用self.window.rootViewController获取当前显示UIViewController,它可能是一种UINavigationViewController或其他类型的视图控制器.我发现可以用来获取屏幕上的visibleViewController属性.但如果它不是,我该怎么办?UINavigationViewControllerUIViewControllerUINavigationViewController

任何帮助表示赞赏!相关代码如下.

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];
}
...
Run Code Online (Sandbox Code Playgroud)

ViewControllerA.m

- (void)handleThePushNotification:(NSDictionary *)userInfo{

    //set some badge view here

}
Run Code Online (Sandbox Code Playgroud)

iphone uiviewcontroller push-notification ios

119
推荐指数
10
解决办法
17万
查看次数

标签 统计

ios ×1

iphone ×1

push-notification ×1

uiviewcontroller ×1