MvvmCross 6 中的子类 UIWindow

Subclass UIWindow in MvvmCross 6

在更新到 MvvmCross 6 之前,我们曾经在 iOS 上继承 UIWindow 并将其设置为 AppDelagate 中的关键窗口以检测应用程序中的所有事件,我们过去使用设置的方式现在已在 MvvmCross 中更改6.0.

https://www.mvvmcross.com/mvvmcross-6.0.0-release/

应用启动

"The way apps start with MvvmCross has now become much cleaner. MvxAppStart is now called automatically by the framework uniformly. This means you can safely delete your initialization code on platforms like iOS (the framework now will also create the key window for you)."

现在看不到设置自己的密钥窗口并将其传递给 MvvmCross 的方法,有什么建议吗?

谢谢

尼尔

正如您所说,MvvmCross 6 现在负责为您分配 KeyWindow。 事实上,在阅读 MvvmCross 6+ 的 source code 时,您可以在 FinishedLanchingWithOptions:

中看到这一点
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        //window is being assigned here by MvvmCross
        if (Window == null)
            Window = new UIWindow(UIScreen.MainScreen.Bounds);

        MvxIosSetupSingleton.EnsureSingletonAvailable(this, Window).EnsureInitialized();

        RunAppStart(launchOptions);

        FireLifetimeChanged(MvxLifetimeEvent.Launching);
        return true;
    }

但是,它们不提供挂钩供您执行此操作。为了解决这个问题,我建议覆盖并做这样的事情:

[Register(nameof(AppDelegate))]
public class AppDelegate : MvxApplicationDelegate<Setup, Core.App>
{
    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        if (Window == null)
            Window = new CustomWindow(UIScreen.MainScreen.Bounds);

        base.FinishedLaunching(application, launchOptions);
    }

}

希望对您有所帮助