问题
My requirement is to open new UIWindow instead story board. Used below code to do this,
UIWindow window = new UIWindow(UIScreen.MainScreen.Bounds);
UIApplication.SharedApplication.KeyWindow.WindowLevel = UIWindowLevel.Normal + 0.1f;
window.RootViewController = new MainNavigationController();
window.MakeKeyAndVisible();
It's working fine in iOS below 13 versions, but not in 13 and above.
Have noted that iOS 13 and above were new update for multi screen, and have introduced scene delegate, so need to move all app delegate stuffs to scene delegate. But in my case there is no code stuff in app delegate and opening this window after my launch screen story board.
is it really required to add scene delegate in existing application? if so how to properly integrate scene delegate in existing application in xamarin iOS?
回答1:
is it really required to add scene delegate in existing application? if so how to properly integrate scene delegate in existing application in xamarin iOS?
You can follow bellow steps to make previous(Before iOS 13) Xamarin.iOS project supports SceneDelegate
used :
First , create a new Xamarin.iOS projecty , copy AppDelegate.cs and SceneDelegate.cs file to root folder of existing project .(AppDelegate.cs
will replcae existing AppDelegate.cs
file , you can move
logic code to SceneDelegate.cs
)
Second , Adding follow code to 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>
More info can refer to this official document : https://docs.microsoft.com/en-us/xamarin/ios/platform/ios13/multi-window-ipad#project-configuration
From iOS 13 , Apple use SceneDelegate.cs
to manage the lifecycle of window .Therefore, you can write code in SceneDelegate.cs
as follow :
[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();
}
Also can refer to this : https://github.com/xamarin/xamarin-macios/issues/7289
来源:https://stackoverflow.com/questions/61783842/window-makekeyandvisible-is-not-showing-new-window-in-ios-13-and-above-os