【问题标题】:didReceiveRemoteNotification and modal viewsdidReceiveRemoteNotification 和模态视图
【发布时间】:2011-10-24 07:02:04
【问题描述】:

我的应用委托有一个 RootViewController *viewController;并且应用会使用此视图启动。

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

我已将应用设置为接收推送通知,并在应用委托中进行了接收远程通知以检索有效负载。

现在问题:

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

【问题讨论】:

    标签: ios delegates push-notification modalviewcontroller


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-16
      • 1970-01-01
      相关资源
      最近更新 更多