Share via

This call site is reachable on: 'iOS' 18.0 and later, 'maccatalyst' 18.0 and later. 'UIWindow' is obsoleted on: 'ios' 26.0 and later (Use the 'UIWindowScene' overload instead.), 'maccatalyst' 26.0 and later (Use the 'UIWindowScene' overload instead.).

Kim Strasser 2,641 Reputation points
2026-06-09T07:05:22.28+00:00

I get these two warnings in my iOS project in Program.cs. Is it necessary to change something or can I ignore the warnings?

This call site is reachable on: 'iOS' 18.0 and later, 'maccatalyst' 18.0 and later. 'UIWindow' is obsoleted on: 'ios' 26.0 and later (Use the 'UIWindowScene' overload instead.), 'maccatalyst' 26.0 and later (Use the 'UIWindowScene' overload instead.).

var Window = new UIWindow(UIScreen.MainScreen.Bounds);

This call site is reachable on: 'iOS' 18.0 and later, 'maccatalyst' 18.0 and later. 'UIApplication.KeyWindow' is obsoleted on: 'ios' 13.0 and later (Should not be used for applications that support multiple scenes because it returns a key window across all connected scenes.), 'maccatalyst' 13.0 and later (Should not be used for applications that support multiple scenes because it returns a key window across all connected scenes.).

var window = UIApplication.SharedApplication.KeyWindow;
namespace MyProjectiOS
{ 
[Register("AppDelegate")]
 class Program : UIApplicationDelegate
 {
     public override UIWindow? Window
     {
         get;
         set;
     }
     private static Game1 game;
     private MyViewController MainViewController;
     private UserNotificationCenterDelegate _notificationDelegate;

     internal static void RunGame()
     {
         int w1 = (int)(UIScreen.MainScreen.Bounds.Size.Width * UIScreen.MainScreen.Scale);
         int h1 = (int)(UIScreen.MainScreen.Bounds.Size.Height * UIScreen.MainScreen.Scale);
         game = new Game1(w1, h1);
         game.Run();
     }

static void Main(string[] args)
{
    UIApplication.Main(args, null, typeof(MyProjectiOS.Program));
} 

public override void FinishedLaunching(UIApplication app)
     {
         CrossMediaManager.Current.Init();

         UIApplication.SharedApplication.IdleTimerDisabled = true;

         // Create and store the delegate
         _notificationDelegate = new UserNotificationCenterDelegate();

         // Request notification permissions from the user  
         UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Alert, (approved, err) => {
             // Handle approval
             if (approved == false)
             {
                 // REQUEST_P0STNOTIFICATIONS Permission Denied
             }

         });

         // Use the stored reference
         UNUserNotificationCenter.Current.Delegate = _notificationDelegate;

         UNUserNotificationCenter.Current.GetNotificationSettings((settings) =>
         {
             if (settings.AuthorizationStatus == UNAuthorizationStatus.NotDetermined || settings.AuthorizationStatus == UNAuthorizationStatus.Denied)
             {
                 InvokeOnMainThread(() =>// in UI thread
                 {
                     var okAlertController = UIAlertController.Create("Title", "go to setting", UIAlertControllerStyle.Alert);

                     //Add Action
                     okAlertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (e) =>
                     {
                         var nurl = NSUrl.FromString(UIApplication.OpenNotificationSettingsUrl);
                         UIApplication.SharedApplication.OpenUrl(nurl!, new NSDictionary(), null); // This line of code will make app go to Notification page. If you test on simulator, the app will jump to Settings page.
                     }));

                     okAlertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));

                     try
                     {
                         var rootVC = UIApplication.SharedApplication.Delegate?.GetWindow()?.RootViewController;
                     }
                     catch(Exception ex)
                     {
                     }

                 });
             }
             else
             {
             }
         });
       
         UIApplication.SharedApplication.RegisterForRemoteNotifications();
        
         var Window = new UIWindow(UIScreen.MainScreen.Bounds);
         MainViewController = new MyViewController();          
         Window.RootViewController = MainViewController;          
         Window.MakeKeyAndVisible(); 
         RunGame();      
}

 public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
      {         
          var window = UIApplication.SharedApplication.KeyWindow;
          if (window != null)
          {
          var vc = window.RootViewController;
          while (vc.PresentedViewController != null)
          {
              vc = vc.PresentedViewController;
          }

          //Create Alert
          var okAlertController = UIAlertController.Create("Remote Notifications", "Failed to register.", UIAlertControllerStyle.Alert);

          //Add Action
          okAlertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));

          // Present Alert
          vc.PresentViewController(okAlertController, true, null);
          }
          else
          {
    
          }
      }

Screenshot 2026-06-02 173556

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

2 answers

Sort by: Most helpful
  1. Nancy Vo (WICLOUD CORPORATION) 5,700 Reputation points Microsoft External Staff Moderator
    2026-06-09T09:29:01.7133333+00:00

    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.

    Was this answer helpful?


  2. AI answer

    2026-06-09T07:05:55.6133333+00:00

    The warnings indicate that the APIs being used are platform‑specific and/or obsolete for the OS versions targeted by the project. They should not be ignored for long‑term compatibility.

    1. new UIWindow(UIScreen.MainScreen.Bounds)

    UIWindow has a constructor that takes a UIWindowScene:

    public UIWindow(UIKit.UIWindowScene windowScene);
    

    For iOS/maccatalyst 26.0 and later, this is the designated initializer. The warning is telling that the bounds‑based initializer is obsolete and that the UIWindowScene overload must be used instead. The correct pattern on scene‑based apps is to create the window from the UIWindowScene provided by the scene delegate and assign it to that scene, for example (conceptually):

    public override void SceneWillConnect(UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
    {
        if (scene is UIWindowScene windowScene)
        {
            Window = new UIWindow(windowScene)
            {
                RootViewController = new MyViewController()
            };
            Window.MakeKeyAndVisible();
        }
    }
    

    This avoids the obsolete constructor and ties the window to the correct scene.

    1. UIApplication.SharedApplication.KeyWindow

    KeyWindow is obsolete for apps that support multiple scenes because it returns a key window across all connected scenes. Instead, the window associated with the current scene should be used. With scene support, the key window is typically obtained from the UIWindowScene (for example, via WindowScene.KeyWindow):

    public virtual UIKit.UIWindow? KeyWindow { get; }
    

    In a scene‑based app, the window reference is usually stored on the scene delegate (or app delegate in MAUI) and reused directly instead of calling KeyWindow.

    1. How to treat the warnings

    These warnings are the .NET platform‑compatibility analyzer (CA1416) and obsoletion messages. The recommended action is to:

    • Call platform‑specific APIs only when running on the appropriate platform and OS version, guarded by OperatingSystem.IsIOS() / OperatingSystem.IsMacCatalyst() checks, or
    • Update code to the newer APIs (UIWindowScene and scene‑based window management) so it remains valid when the app runs on newer OS versions.

    If the app is intended to run on iOS/maccatalyst versions where UIWindow and KeyWindow are obsolete, the code should be updated rather than suppressing the warnings. Suppression (via #pragma or analyzer configuration) is only appropriate when there is a deliberate decision to keep the old API and the deployment targets guarantee that the obsolete paths will not be hit.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.