From 8a97f0ac5b3a952ea66ff13c36db5dd320a5bad1 Mon Sep 17 00:00:00 2001 From: Emilien Dup Date: Mon, 9 Jan 2023 09:07:35 +0100 Subject: [PATCH] fix/#753: iOS: Change UIScene selection logic Only select UIScene that is rendered on the device built in display --- .../Platforms/Ios/Impl/PopupPlatformIos.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Rg.Plugins.Popup/Platforms/Ios/Impl/PopupPlatformIos.cs b/Rg.Plugins.Popup/Platforms/Ios/Impl/PopupPlatformIos.cs index cd1cd48f..e2dc382b 100644 --- a/Rg.Plugins.Popup/Platforms/Ios/Impl/PopupPlatformIos.cs +++ b/Rg.Plugins.Popup/Platforms/Ios/Impl/PopupPlatformIos.cs @@ -55,9 +55,24 @@ public Task AddAsync(PopupPage page) PopupWindow window; if (IsiOS13OrNewer) { - if (UIApplication.SharedApplication.ConnectedScenes.ToArray() - .FirstOrDefault(x => x.ActivationState == UISceneActivationState.ForegroundActive && x is UIWindowScene) is UIWindowScene connectedScene) - window = new PopupWindow(connectedScene); + var connectedWindowScene = UIApplication.SharedApplication + .ConnectedScenes + .ToArray() + .FirstOrDefault(scene => + { + // The popup should only be displayed on a scene that displays interactive windows + // on the device’s built-in display or an externally connected display. + if (scene.Session?.Role != UIWindowSceneSessionRole.Application) + { + return false; + } + + return scene.ActivationState == UISceneActivationState.ForegroundActive + && scene is UIWindowScene; + }) as UIWindowScene; + + if (connectedWindowScene != null) + window = new PopupWindow(connectedWindowScene); else window = new PopupWindow();