Exception on Deactivated in Maui .NET8 ios app

128 views Asked by At

I use iOS binding library which creates its own UIWindow. It is used, for example, for user authorization and then this UIWindow can become key window. Note that we have here two UIWindows: one from binding library and one created by Maui in CreatePlatformWindow (https://github.com/dotnet/maui/blob/8.0.3/src/Core/src/Platform/iOS/ApplicationExtensions.cs#L103).

The problem is that if AppDelegate.OnActivated is invoked when UIWindow from binding library is key window, then IWindow.Activated (https://github.com/dotnet/maui/blob/8.0.3/src/Controls/src/Core/Window/Window.cs#L501) is not called and IsActivated is not set for any Window (as it is called only if platform window created by Maui is the key window). If this is the case then exception will be thrown when platform window created by Maui become key window again and app is moved to background: https://github.com/dotnet/maui/blob/8.0.3/src/Controls/src/Core/Window/Window.cs#L514

I created workaround and call AppDelegate.OnActivated when DidBecomeKeyNotification is received for platform window created by Maui. It seems to work but maybe someone has an idea for more elegant solution.

btw... is it possible to replace UIWindow created here: https://github.com/dotnet/maui/blob/8.0.3/src/Core/src/Platform/iOS/ApplicationExtensions.cs#L107 by other already existing UIWindow (like the one from binding library)?

0

There are 0 answers