gpt4 book ai didi

ios - Xamarin iOS : Unable to start new ViewController by tapping on remote notifications

转载 作者:行者123 更新时间:2023-11-29 11:36:36 27 4
gpt4 key购买 nike

我在 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;
}
}

在通知点击时,我正在使用单独的嵌套类 CustomUNUserNotificationCenterDelegate,它不会使用更新的数据启动 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);
}
}
ChildrenViewController

ViewDidLoad() 我在这里检查应用程序是通过点击启动还是通过点击通知启动,以便我分配不同的数据

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

this.AutomaticallyAdjustsScrollViewInsets = false;

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

最佳答案

在委托(delegate)方法DidReceiveNotificationResponse中,看一下代码,

var nv = new UINavigationController();
nv.PushViewController(cvc, false);

您在这里所做的是,您正在创建一个新的导航 Controller 并尝试将 subview Controller 推送到这个新创建的导航 Controller 堆栈。这里的问题是,您在此处创建的导航 Controller 未设置为窗口的 Root View Controller 。

你可以做的是,将这个新创建的导航 VC 设置为你的 Root View Controller ,如果这是你想要做的,或者获取窗口的 Root View Controller 的引用,正如我从你的代码中看到的那样,它是一个导航 Controller ,并且尝试将 subview Controller 推到它上面。

希望这对您有所帮助。

关于ios - Xamarin iOS : Unable to start new ViewController by tapping on remote notifications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48866446/

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