C# Window.MakeKeyAndVisible()未在iOS 13及更高版本的操作系统中显示新窗口

C# Window.MakeKeyAndVisible()未在iOS 13及更高版本的操作系统中显示新窗口,c#,swift,xamarin,xamarin.ios,ios13,C#,Swift,Xamarin,Xamarin.ios,Ios13,我的要求是打开新的UIWindow而不是story board。 使用下面的代码来执行此操作 UIWindow window = new UIWindow(UIScreen.MainScreen.Bounds); UIApplication.SharedApplication.KeyWindow.WindowLevel = UIWindowLevel.Normal + 0.1f; window.RootViewController

我的要求是打开新的UIWindow而不是story board。 使用下面的代码来执行此操作

UIWindow window = new UIWindow(UIScreen.MainScreen.Bounds);
                UIApplication.SharedApplication.KeyWindow.WindowLevel = UIWindowLevel.Normal + 0.1f;

                window.RootViewController = new MainNavigationController();
                window.MakeKeyAndVisible();
它在13以下版本的iOS中运行良好,但在13及以上版本中则不行

注意到iOS 13及以上版本是针对多屏幕的新更新,并引入了场景代理,因此需要将所有应用程序代理内容移动到场景代理。但在我的例子中,app delegate中没有代码,在我发布屏幕故事板后打开此窗口

是否确实需要在现有应用程序中添加场景代理?如果是这样,如何在xamarin iOS中的现有应用程序中正确集成场景代理

是否确实需要在现有应用程序中添加场景代理?如果是这样,如何在xamarin iOS中的现有应用程序中正确集成场景代理

您可以按照以下步骤使以前(iOS 13之前)的Xamarin.iOS项目支持
SceneDelegate
使用:

首先,创建一个新的Xamarin.iOS项目,将AppDelegate.csSceneDelegate.cs文件复制到现有项目的根文件夹。(
AppDelegate.cs
将复制现有的
AppDelegate.cs
文件,您可以移动 逻辑代码到
SceneDelegate.cs

Second,将以下代码添加到Info.plist

<key>UIApplicationSceneManifest</key>
<dict>
  <key>UIApplicationSupportsMultipleScenes</key>
  <false/>
  <key>UISceneConfigurations</key>
  <dict>
    <key>UIWindowSceneSessionRoleApplication</key>
    <array>
      <dict>
        <key>UISceneConfigurationName</key>
        <string>Default Configuration</string>
        <key>UISceneDelegateClassName</key>
        <string>SceneDelegate</string>
        <key>UISceneStoryboardFile</key>
        <string>Main</string>
      </dict>
    </array>
  </dict>
</dict>

也可以参考以下内容:

谢谢@Junior,但在我的场景中,仅在启动屏幕后打开新的UIWindow()。将UIApplicationSupportsMultipleScenes值更改为false对我来说是可行的,我已经在参考链接中注意到了这一点,再次感谢。@Naveenraj Okey,很高兴它能起作用。这是一个示例代码,您可以根据需要修改配置。关键点是
UISceneConfigurations
,它将在项目中使用
SceneDelegate
。如果答案有帮助,记得在有时间的时候记下:-)
[Export ("scene:willConnectToSession:options:")]
public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
{
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see UIApplicationDelegate `GetConfiguration` instead).
    UIWindowScene windowScene = new UIWindowScene(session, connectionOptions);

    var storyboard = UIStoryboard.FromName("Main", null);

    var registerController = storyboard.InstantiateViewController("ViewControllerSecond") as ViewControllerSecond;
    this.Window = new UIWindow(windowScene);
    this.Window.RootViewController = registerController;
    this.Window.MakeKeyAndVisible();
}