iosswiftobjective-cxamarinuiscenedelegate

iOS Convering an Old project to use UI


I am trying to convert (slowly mordenize) an old iOS project to support UISceneDelegate. However at the moment the old appdelegate creates a UIWindow and attaches a UIViewController to the windows rootViewController in the finishedLaunching.

As I am not ready to convert my application to Storyboards yet is there a way I can achieve the same result using UISceneDelegate ?

Please note the mainViewController is not backed by a XIB or a storyboard so there is no reference to any UI Files in the UIWindowSceneSessionRoleApplication portion of my info.plist

Regards Christian Stœr Andersen


Solution

  • If you're developing Xamairn.iOS, here is the sample.

    Remain the code in AppDelegate , and add the following code into SceneDelegate .

    [Export ("scene:willConnectToSession:options:")]
    public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
    {
        UIWindowScene windowScene = scene as UIWindowScene;
        Window = new UIWindow(windowScene);
        Window.Frame = windowScene.CoordinateSpace.Bounds;
        Window.RootViewController = new YourViewController();
        Window.MakeKeyAndVisible ();            
    }