Xamarin iOS:无法通过点击远程通知启动新的ViewController

Xamarin iOS:无法通过点击远程通知启动新的ViewController,ios,uiviewcontroller,xamarin.ios,Ios,Uiviewcontroller,Xamarin.ios,我正在iOS上工作,实现了FCM远程通知。当我点击通知(当应用程序打开时)时,它不会启动另一个屏幕。请参阅下面我正在使用的代码 在这里,当应用程序启动时,我通过点击打开ChildrenViewController public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { Window = new UIWindow(UI

我正在iOS上工作,实现了FCM远程通知。当我点击通知(当应用程序打开时)时,它不会启动另一个屏幕。请参阅下面我正在使用的代码

在这里,当应用程序启动时,我通过点击打开
ChildrenViewController

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {  

            Window = new UIWindow(UIScreen.MainScreen.Bounds);
            UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;

                 var cvc = new ChildrenViewController();
                 cvc.childs = SISConst.Mychildren;
                 this.navCntl = new UINavigationController(cvc);
                 this.navCntl.NavigationBarHidden = true;
                 Window.MakeKeyAndVisible();
                 SetRootViewController(this.navCntl, false);
         }

public void SetRootViewController(UIViewController rootViewController, bool animate)
        {
            if (animate)
            {
                var transitionType = UIViewAnimationOptions.TransitionFlipFromRight;
                if (Window == null)
                {
                    Window = new UIWindow(UIScreen.MainScreen.Bounds);
                }
                Window.RootViewController = rootViewController;
                UIView.Transition(Window, 0.5, transitionType,
                                  () => Window.RootViewController = rootViewController,
                                  null);
            }
            else
            {
                Window.RootViewController = rootViewController;
            }
        }
在通知中,单击“我正在使用单独的嵌套类”
CustomUnuseNotificationCenterDelegate
,该类未使用更新的数据启动
ChildrenViewController

     public class CustomUNUserNotificationCenterDelegate : UNUserNotificationCenterDelegate
        {
            public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
                    {
                        completionHandler();
                        var cvc = new ChildrenViewController();
                        cvc.studentId=studentId;
                        cvc.moduleName = moduleName;
                        cvc.isPush = true;
                        //var nv = new UINavigationController();
                        var appdelegate=UIApplication.SharedApplication.Delegate as AppDelegate;               
                        //appdelegate.Window.RootViewController = nv; 
                        var nv = appdelegate.Window.RootViewController as UINavigationController;                      
                        nv.PushViewController(cvc, false);         
                    }
        }
viewdiload()
ChildrenViewController
这里我检查应用程序是通过单击启动还是通过点击通知启动,以便分配不同的数据

public override void ViewDidLoad()
{
    base.ViewDidLoad();
    this.ShowStatusBarWithWhiteBg();
    this.DesignScreenTitleAs("");
    this.DesignLogoAppTitle();

    this.AutomaticallyAdjustsScrollViewInsets = false;

    if (isPushNotification)
    {            
        ShowDashboardScreen();
    }
    else
    {             
        ShowChilds();
    }
}

在委托方法DidReceiveNotificationResponse中,查看代码

var nv = new UINavigationController();
nv.PushViewController(cvc, false); 
这里要做的是,创建一个新的导航控制器,并尝试将子视图控制器推送到这个新创建的导航控制器堆栈中。这里的问题是,您在这里创建的导航控制器未设置为窗口的根视图控制器

你可以做的是,如果你想做的话,将这个新创建的导航VC设置为你的根视图控制器,或者获取窗口的根视图控制器的引用,正如我从你的代码中看到的,它是一个导航控制器,并试着将子视图控制器推到它上面


希望这有帮助。

@Yogish查看我被分配的更新代码
RootView
。我仍然无法推送new
ViewController
。app delegate是一个单例类,您不应该在新代码中创建app delegate类的新实例。此外,不应创建新窗口。您可以使用UIApplication的shared()方法获取已创建的应用程序委托,然后访问应用程序委托的窗口,将根视图控制器强制转换为导航控制器,然后推送您的子视图控制器。@Yogish您的答案对我有效。我已经更新了工作代码。@PriyankaAgrawal我的一个建议是,不要再次更改DidReceiveNotificationResponse()中的rootviewcontroller。因为,您已经在FinishedLaunching()中将导航控制器设置为根视图控制器访问同一根视图控制器并推送您的孩子vc。@Yogish您的建议很好,解决了导航问题。我也尝试过更新代码,我做得对吗?