gpt4 book ai didi

ios - didReceiveRemoteNotification 和模态视图

转载 作者:行者123 更新时间:2023-11-29 04:56:28 25 4
gpt4 key购买 nike

我的应用程序委托(delegate)有一个 RootViewController *viewController;应用程序将以此 View 启动。

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

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

现在问题:

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

最佳答案

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

@property (nonatomic, retain) UIViewController *currentModalViewController;

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

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

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

关于ios - didReceiveRemoteNotification 和模态视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7872238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com