didReceiveRemoteNotification 和模态视图

发布于 2024-12-11 19:25:24 字数 326 浏览 0 评论 0原文

我的应用程序委托有一个 RootViewController *viewController;并且应用程序会以该视图启动。

从现在开始,当用户导航到应用程序内的不同功能时,我将继续呈现模态视图(最多 3 级)。

我已将应用程序设置为接收推送通知,并且在应用程序委托内设置了 didReceiveRemoteNotification 来检索有效负载。

现在的问题是:

  1. 当收到推送通知时,我如何知道用户当前处于哪个模式视图?
  2. 如何关闭所有模态视图以返回到 RootViewController?我真的可以在应用程序委托中执行此操作吗?

My app delegate has a RootViewController *viewController; and the app launches with this view.

From here on I will continue to present modal views (up to 3 levels) as the user navigates to different functions within the app.

I have setup the app to receive push notifications, and I have didReceiveRemoteNotification inside the app delegate to retrieve the payload.

Now the questions:

  1. When the push notification is received, how can I know which modal view the user is currently in?
  2. How do I close all the modal views to return to the RootViewController? Can I actually do this within the app delegate?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇 2024-12-18 19:25:24

没有通用的内置方法可以做到这一点。最好的解决方案可能是向您的应用程序委托添加一个属性,您可以在其中存储它。

@property (nonatomic, retain) UIViewController *currentModalViewController;

当您呈现模态视图控制器时,请执行以下操作:

#import "MyAppDelegate.h"

// ....
MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.currentModalViewController = vc;
[self presentModalViewController:vc animated:YES];

您还需要确保在关闭时丢失引用:

[self dismissModalViewControllerAimated:YES];
MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.currentModalViewController = nil;

然后在您的应用程序委托中,您拥有关闭当前模态视图控制器并检查是否有模态所需的一切查看当前存在的控制器。

There's no generic built-in way of doing this. The best solution is probably to add a property to your app delegate where you can store it.

@property (nonatomic, retain) UIViewController *currentModalViewController;

When you present modal view controllers, do this:

#import "MyAppDelegate.h"

// ....
MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.currentModalViewController = vc;
[self presentModalViewController:vc animated:YES];

You also need to make sure you lose the reference when dismissing:

[self dismissModalViewControllerAimated:YES];
MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.currentModalViewController = nil;

Then in your app delegate, you have everything you need in order to dismiss the current modal view controller and check if there is a modal view controller present at the moment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文