Support for Scene-Based Life Cycle in the iOS template
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MonoGame/MonoGame.Templates
-
broken link websiteOpen
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
Difficulty 3/5 Half a day Newbie friendliness 55/100
-
Content Builder should output it's execution statement at the start of its runMay be free again @SimonDarksideJ claimed this 285 days ago, and no pull request is open. Open
MonoGame/MonoGame.Templates#39 · 2 comments · 1 assignee ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
MonoGame/MonoGame.Templates#16 · 1 comment ·
All issues in MonoGame/MonoGame.Templates
Similar issues
-
type:task ux
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
elsa-workflows/elsa-foundation#5253 ·
Maintainers usually reply within 1 day