如何将响应通知的模态视图显示为新窗口? (没有父vc)

我有很多问题处理我的传入本地通知。 我的应用程序正在使用故事板,并有一个tabbarcontroller作为rootviewcontroller。 目前,我通过以下方式从“didReceiveLocalNotification”启动模态视图:

MedicationReminderViewController *vc = [[MedicationReminderViewController alloc] initWithNibName:@"MedicationReminderViewController" bundle:nil]; vc.notificationInfo = [[NSDictionary alloc] initWithDictionary:notification.userInfo]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc]; navController.navigationBar.barStyle = UIBarStyleBlackOpaque; navController.title = @"title"; UITabBarController *tc = (UITabBarController *)self.window.rootViewController; UINavigationController *nc = (UINavigationController *)tc.selectedViewController; [[nc visibleViewController] presentModalViewController:navController animated:YES]; 

这有效,但不是在任何场合。 我想在新窗口中显示当时可以显示的任何其他模态视图。 当用户处理传入的通知时,模式视图将自行消除,并且在通知进入之前活动的基础视图将再次可见。 我怎样才能做到这一点?

window对象的AppDelegate中执行此操作。 我相信你可以在那里做。 从我的头顶,我相信它的window.rootViewController。 虽然不确定。

怎么做:当你收到你的UILocalNotification,你可以在AppDelegate中收到它。 当通知“到达”时,使用self.window.rootViewController上的presentModalViewController

更新
从文档 :

如果应用程序是最重要的,并且在系统发送通知时可见,则不显示警报,不显示图标,也不播放声音。 但是, 应用程序:didReceiveLocalNotification:如果应用程序委托实现它,则会被调用。 UILocalNotification实例被传递给这个方法,委托可以检查它的属性,或者访问userInfo字典中的任何自定义数据。

使用application:didReceiveLocalNotification:方法。 我希望能回答你的问题。