Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS 13+ always uses the scenes if there is one registered in the manifest #3454

Merged
merged 5 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Core/src/Platform/iOS/HandlerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Microsoft.Maui
{
public static class HandlerExtensions
{
const string UIApplicationSceneManifestKey = "UIApplicationSceneManifest";

internal static UIView? GetNative(this IElement view, bool returnWrappedIfPresent)
{
if (view.Handler is INativeViewHandler nativeHandler && nativeHandler.NativeView != null)
Expand Down Expand Up @@ -74,6 +76,12 @@ public static INativeViewHandler ToHandler(this IElement view, IMauiContext cont
return (INativeViewHandler)handler;
}

// If < iOS 13 or the Info.plist does not have a scene manifest entry we need to assume no multi window, and no UISceneDelegate.
// We cannot check for iPads/Mac because even on the iPhone it uses the scene delegate if one is specified in the manifest.
public static bool HasSceneManifest(this UIApplicationDelegate nativeApplication) =>
UIDevice.CurrentDevice.CheckSystemVersion(13, 0) &&
NSBundle.MainBundle.InfoDictionary.ContainsKey(new NSString(UIApplicationSceneManifestKey));

public static void SetApplicationHandler(this UIApplicationDelegate nativeApplication, IApplication application, IMauiContext context) =>
SetHandler(nativeApplication, application, context);

Expand Down
20 changes: 12 additions & 8 deletions src/Core/src/Platform/iOS/MauiUIApplicationDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.Maui
public abstract class MauiUIApplicationDelegate : UIApplicationDelegate, IUIApplicationDelegate
{
internal const string MauiSceneConfigurationKey = "__MAUI_DEFAULT_SCENE_CONFIGURATION__";
internal const string GetConfigurationSelectorName = "application:configurationForConnectingSceneSession:options:";

IMauiContext _applicationContext = null!;

Expand Down Expand Up @@ -43,21 +44,24 @@ public override bool FinishedLaunching(UIApplication application, NSDictionary l

this.SetApplicationHandler(Application, _applicationContext);

// If < iOS 13, or we're not on mac/ipad, or the Info.plist does not have a scene manifest entry
// we need to assume no multi window, and no UISceneDelegate
if (!UIDevice.CurrentDevice.CheckSystemVersion(13, 0)
|| (UIDevice.CurrentDevice.UserInterfaceIdiom != UIUserInterfaceIdiom.Mac
&& UIDevice.CurrentDevice.UserInterfaceIdiom != UIUserInterfaceIdiom.Pad)
|| !NSBundle.MainBundle.InfoDictionary.ContainsKey(new NSString("UIApplicationSceneManifest")))
{
// if there is no scene delegate or support for scene delegates, then we set up the window here
if (!this.HasSceneManifest())
this.CreateNativeWindow(Application, application, launchOptions);
}

Services?.InvokeLifecycleEvents<iOSLifecycle.FinishedLaunching>(del => del(application!, launchOptions!));

return true;
}

public override bool RespondsToSelector(Selector? sel)
{
// if the app is not a multi-window app, then we cannot override the GetConfiguration method
if (sel?.Name == GetConfigurationSelectorName && !this.HasSceneManifest())
return false;

return base.RespondsToSelector(sel);
}

public override UISceneConfiguration GetConfiguration(UIApplication application, UISceneSession connectingSceneSession, UISceneConnectionOptions options)
=> new(MauiUIApplicationDelegate.MauiSceneConfigurationKey, connectingSceneSession.Role);

Expand Down