如何将模态视图响应通知显示为新窗口?(没有父 vc) [英] How can I show a modal view in response to a notification as a new window? (no parent vc)

查看:22
本文介绍了如何将模态视图响应通知显示为新窗口?(没有父 vc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am having a lot of issues handling my incoming local notifications. My app is using storyboards and has a tabbarcontroller as the rootviewcontroller. Currently I launch the modalviews from 'didReceiveLocalNotification' in the following manner:

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];

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

This works but not on all occasions. I'd like to present the modal view in a new window over anything else that could be displayed at that time. When the user handles the incoming notification the modal view will dismiss itself and the underlying view that was active before the notification came in will be visible again. How can I achieve this?

推荐答案

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

Do it in your AppDelegate on the window object. I believe you could do it there. From the top of my head, I believe its the window.rootViewController. Unsure though.

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

How to do it: When you recieve your UILocalNotification, you can recieve it in the AppDelegate. When the notification "arrives", use the presentModalViewController on self.window.rootViewController.

更新
来自 文档:

如果应用程序在系统交付时最重要且可见通知,没有显示警报,没有图标被标记,也没有声音玩过的.但是,application:didReceiveLocalNotification: 是如果应用程序委托实现它,则调用它.这UILocalNotification 实例被传递到这个方法中,并且委托可以检查其属性或访问任何自定义数据用户信息字典.

If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it. The UILocalNotification instance is passed into this method, and the delegate can check its properties or access any custom data from the userInfo dictionary.

使用 application:didReceiveLocalNotification: 方法.我希望回答了您的问题.

Use the application:didReceiveLocalNotification: method. I hope that answered your question.

这篇关于如何将模态视图响应通知显示为新窗口?(没有父 vc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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