【发布时间】:2012-11-16 12:39:02
【问题描述】:
我正在使用 storyboard ,我希望在用户收到远程推送通知时始终打开相同的视图,即使应用程序在后台或已打开。我需要呈现的视图是在情节提要中设置的初始视图控制器之后的四个视图。我读了这篇文章:
How can I show a modal view in response to a notification as a new window? (no parent vc)
Open a specific tab/view when user receives a push notification
这是我的代码:
- (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];
}
但是当我收到通知时,应用程序崩溃并出现以下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[locationViewController setViewControllers:]: unrecognized selector sent to instance 0x42ccd0'
locationViewController 是在情节提要中设置为初始的视图控制器。
非常感谢。
【问题讨论】:
-
假设“HomeViewController”是Storyboard中的初始视图控制器,点击一个按钮后,通过push方法进入“SecondViewController”。现在,您将收到推送通知。您是要推送“NotificationViewController”还是模态呈现?
-
Modally,所以我不确定你的解释,你建议推送堆栈直到我得到notificacionViewController?谢谢
标签: objective-c ios apple-push-notifications