Skip to content

Commit

Permalink
[iOS] Crash upon resuming the app - fix (dotnet#21948)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo authored and PureWeen committed Jul 5, 2024
1 parent 7785fea commit a202796
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ static void OnConfigureLifeCycle(IiOSLifecycleBuilder iOS)
.WillTerminate(app =>
{
// By this point if we were a multi window app, the GetWindow would be null anyway
app.GetWindow()?.Destroying();
app.GetFirstWindow()?.Destroying();
KeyboardAutoManagerScroll.Disconnect();
})
.WillEnterForeground(app =>
{
if (!app.Delegate.HasSceneManifest())
app.GetWindow()?.Resumed();
app.GetFirstWindow()?.Resumed();
})
.OnActivated(app =>
{
if (!app.Delegate.HasSceneManifest())
app.GetWindow()?.Activated();
app.GetFirstWindow()?.Activated();
})
.OnResignActivation(app =>
{
if (!app.Delegate.HasSceneManifest())
app.GetWindow()?.Deactivated();
app.GetFirstWindow()?.Deactivated();
})
.DidEnterBackground(app =>
{
if (!app.Delegate.HasSceneManifest())
app.GetWindow()?.Stopped();
app.GetFirstWindow()?.Stopped();
});


Expand Down
11 changes: 11 additions & 0 deletions src/Core/src/Platform/iOS/UIApplicationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ internal static UIEdgeInsets GetSafeAreaInsetsForWindow(this UIApplication appli
public static IWindow? GetWindow(this UIApplication application) =>
application.GetKeyWindow().GetWindow();

public static IWindow? GetFirstWindow(this UIApplication application)
{
#pragma warning disable CA1422 // Validate platform compatibility
var windows = application.Windows;
#pragma warning restore CA1422 // Validate platform compatibility

var window = windows.Length > 0 ? windows[0] : null;

return window.GetWindow();
}

public static IWindow? GetWindow(this UIWindow? platformWindow)
{
if (platformWindow is null)
Expand Down

0 comments on commit a202796

Please sign in to comment.