接收远程推送通知时,打开视图控制器 [英] Open view controller when receiving remote Push Notification

查看:155
本文介绍了接收远程推送通知时,打开视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用故事板,我想,当用户收到远程推送通知,要始终打开相同的观点,即使该应用程序在后台或打开。我需要present的看法是在故事板设定初始视图控制器后,四点看法。我读这帖子:

I'm using storyboard , and I want to open always the same view when user receives remote push notifications, even the app is in background or opened. The view I need to present is four views after the initial view controller set in the storyboard. I read this posts:

<一个href=\"http://stackoverflow.com/questions/10430860/how-can-i-show-a-modal-view-in-response-to-a-notification-as-a-new-window-no-p\">How我可以显示在响应通知作为一个新的窗口,一个模式的看法? (无父VC)

<一个href=\"http://stackoverflow.com/questions/6734338/open-a-specific-tab-view-when-user-receives-a-push-notification\">Open一个特定的选项卡/视图时,用户会收到一个推送通知

因此​​,这里是我的code:

So here is my code:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
    notificacionViewController *menu = [navController.storyboard instantiateViewControllerWithIdentifier:@"notificacion"];

    // First item in array is bottom of stack, last item is top.
    navController.viewControllers = [NSArray arrayWithObjects:menu,nil];

    [self.window makeKeyAndVisible];


}

但是,当我收到通知,应用程序与此错误崩溃:

But when I receive notification, the app crashes with this error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[locationViewController setViewControllers:]: unrecognized selector sent to instance 0x42ccd0'

locationViewController是在故事板设置为初始视图控制器。

locationViewController is the view controller set as initial in the storyboard.

非常感谢。

推荐答案

请尝试以下code:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
    NotificationViewController *notificationViewController = [[NotificationViewController alloc] init];
    [navController.visibleViewController.navigationController pushViewController:notificationViewController];    
}

这篇关于接收远程推送通知时,打开视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆