0

我在处理传入的本地通知时遇到了很多问题。我的应用程序正在使用情节提要,并有一个 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];

这有效,但并非在所有情况下都有效。我想在新窗口中显示模态视图,而不是当时可以显示的任何其他内容。当用户处理传入的通知时,模态视图将自行关闭,并且在通知传入之前处于活动状态的底层视图将再次可见。我怎样才能做到这一点?

4

1 回答 1

0

window对象上的 AppDelegate 中执行此操作。我相信你可以在那里做到。从我的脑海中,我相信它是 window.rootViewController。不过不确定。

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


文档更新

如果在系统传递通知时应用程序处于最前面且可见,则不会显示警报,不会标记图标,也不会播放声音。但是,如果应用程序委托实现了application:didReceiveLocalNotification: ,则会调用它。UILocalNotification 实例被传递到此方法中,并且委托可以检查其属性或访问 userInfo 字典中的任何自定义数据。

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

于 2012-05-03T11:57:33.823 回答