Support for Scene-Based Life Cycle in the iOS template

Open
#65 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp, ios
Domain
mobile-dev

Research direction

Start by locating the iOS template's generated Program.cs and inspect how it currently initializes the AppDelegate-centric lifecycle. Compare it with the SceneDelegate-based flow described in the issue, then generate an iOS project and verify that it launches on the stated .NET iOS workload without requiring additional Info.plist entries.

Written by the indexing model from the issue text.

Description

In the current iOS template, the traditional AppDelegate-centric lifecycle is used, which causes the app to fail to launch on iOS 27, where the Scene-Based Life Cycle using SceneDelegate has become mandatory.

To solve this problem, I modified the Program.cs generated by the template as follows:

using UIKit;

namespace MGNamespace
{
    // The [Register] attribute is not necessary.
    internal class Program : UIResponder, IUIApplicationDelegate, IUIWindowSceneDelegate // This class implements both interfaces so that it can serve as both the AppDelegate and SceneDelegate. If the classes are separated, UIApplicationDelegate and UIWindowSceneDelegate, which are classes rather than interfaces, can also be used as base classes.
    {
        static void Main(string[] args)
        {
            UIApplication.Main(args, null, typeof(Program));; // Use this class as the AppDelegate
        }

        public UISceneConfiguration GetConfiguration(UIApplication application, UISceneSession connectingSceneSession, UISceneConnectionOptions options)
        {
            UISceneConfiguration configuration = new UISceneConfiguration("Default Configuration", connectingSceneSession.Role); // The configuration name can be arbitrary.
            configuration.DelegateType = typeof(Program); // Use this class as the SceneDelegate
            return configuration;
        }

        public void WillConnect(UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
        {
            if (scene is not UIWindowScene windowScene)
            {
                return;
            }

            Game1 game = new Game1();
            UIWindow window = game.Services.GetService<UIWindow>();
            window.WindowScene = windowScene; // Get the UIWindow initialized by iOSGamePlatform and assign its UIWindowScene.
            game.Run();
        }
    }
}

Also, since the delegate class is specified in the code, no additional entries in Info.plist are required.

Environment:
.NET SDK: 10.0.401
.NET iOS Workload: 27.0.10722
Xcode: 27.0

Dominant language
C#
Stars
11
Forks
11
Avg merge
18h 53m
Merged PRs (30d)
1

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MonoGame/MonoGame.Templates

All issues in MonoGame/MonoGame.Templates

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.