A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello @Kim Strasser ,
Thanks for your question.
Since var Window creates a local variable that shadows the class property Window - your window may be lost/garbage collected. Furthermore, UIWindow(UIScreen.MainScreen.Bounds) is obsoleted on iOS 26+, Apple wants you to use UIWindowScene instead.
I recommend replacing this code:
var window = new UIWindow(UIScreen.MainScreen.Bounds);
with:
public override void FinishedLaunching(UIApplication app)
{
var windowScene = app.ConnectedScenes
.OfType<UIWindowScene>()
.FirstOrDefault();
if (windowScene != null)
{
Window = new UIWindow(windowScene);
}
MainViewController = new MyViewController();
Window!.RootViewController = MainViewController;
Window!.MakeKeyAndVisible();
RunGame();
}
Regarding the second warning, I suggest updating the relevant method as follows:
Platforms/iOS/AppDelegate.cs:
public override void FailedToRegisterForRemoteNotifications(
UIApplication application, NSError error)
{
var windowScene = UIApplication.SharedApplication
.ConnectedScenes
.OfType<UIWindowScene>()
.FirstOrDefault(s => s.ActivationState ==
UISceneActivationState.ForegroundActive);
var window = windowScene?.Windows
.FirstOrDefault(w => w.IsKeyWindow)
?? windowScene?.Windows.FirstOrDefault();
if (window != null)
{
var vc = window.RootViewController;
while (vc?.PresentedViewController != null)
{
vc = vc.PresentedViewController;
}
var okAlertController = UIAlertController.Create(
"Remote Notifications",
"Failed to register.",
UIAlertControllerStyle.Alert);
okAlertController.AddAction(
UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
vc?.PresentViewController(okAlertController, true, null);
}
}
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.