15#include <qpa/qplatformintegration.h>
17#include <QtCore/QtCore>
19@interface QIOSWindowSceneDelegate : NSObject<UIWindowSceneDelegate>
20@property (nullable, nonatomic, strong) UIWindow *window;
23@implementation QIOSApplicationDelegate
25- (UISceneConfiguration *)application:(UIApplication *)application
26 configurationForConnectingSceneSession:(UISceneSession *)session
27 options:(UISceneConnectionOptions *)options
29 qCDebug(lcQpaWindowScene) <<
"Configuring scene for" << session <<
"with options" << options;
31 auto *sceneConfig = session.configuration;
33 if ([sceneConfig.role hasPrefix:@
"CPTemplateApplication"]) {
34 qCDebug(lcQpaWindowScene) <<
"Not touching CarPlay scene with role" << sceneConfig.role
35 <<
"and existing delegate class" << sceneConfig.delegateClass;
39 sceneConfig.delegateClass = QIOSWindowSceneDelegate.
class;
47@implementation QIOSWindowSceneDelegate
49- (
void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions
51 qCDebug(lcQpaWindowScene) <<
"Connecting" << scene <<
"to" << session;
54 const auto handleConnectionOptions = qScopeGuard([&]{
55 if (connectionOptions.URLContexts.count > 0)
56 [self scene:scene openURLContexts:connectionOptions.URLContexts];
58 for (NSUserActivity *activity in connectionOptions.userActivities)
59 [self scene:scene continueUserActivity:activity];
62#if defined(Q_OS_VISIONOS)
66 if ([scene.session.role isEqualToString:@
"CPSceneSessionRoleImmersiveSpaceApplication"]) {
67 qCDebug(lcQpaWindowScene) <<
"Skipping UIWindow creation for immersive scene";
72 if (![scene isKindOfClass:UIWindowScene.
class]) {
73 qCWarning(lcQpaWindowScene) <<
"Unexpectedly encountered non-window scene";
77 UIWindowScene *windowScene =
static_cast<UIWindowScene*>(scene);
79 QUIWindow *window = [[QUIWindow alloc] initWithWindowScene:windowScene];
80 window.rootViewController = [[[QIOSViewController alloc] initWithWindow:window] autorelease];
82 self.window = [window autorelease];
85- (
void)windowScene:(UIWindowScene *)windowScene
86 didUpdateCoordinateSpace:(id<UICoordinateSpace>)previousCoordinateSpace
87 interfaceOrientation:(UIInterfaceOrientation)previousInterfaceOrientation
88 traitCollection:(UITraitCollection *)previousTraitCollection
90 qCDebug(lcQpaWindowScene) <<
"Scene" << windowScene <<
"did update properties";
94 Q_ASSERT([self.window isKindOfClass:QUIWindow.
class]);
95 auto *viewController =
static_cast<QIOSViewController*>(self.window.rootViewController);
96 [viewController updatePlatformScreen];
99- (
void)sceneDidDisconnect:(UIScene *)scene
101 qCDebug(lcQpaWindowScene) <<
"Disconnecting" << scene;
105- (
void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts
107 qCDebug(lcQpaWindowScene) <<
"Handling openURLContexts for scene" << scene;
109 QIOSIntegration *iosIntegration = QIOSIntegration::instance();
110 Q_ASSERT(iosIntegration);
112 QIOSServices *iosServices =
static_cast<QIOSServices *>(iosIntegration->services());
114 for (UIOpenURLContext *urlContext in URLContexts)
115 iosServices->handleUrl(QUrl::fromNSURL(urlContext.URL));
118- (
void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity
120 qCDebug(lcQpaWindowScene) <<
"Handling user activity for scene" << scene;
122 if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
123 QIOSIntegration *iosIntegration = QIOSIntegration::instance();
124 Q_ASSERT(iosIntegration);
126 QIOSServices *iosServices =
static_cast<QIOSServices *>(iosIntegration->services());
127 iosServices->handleUrl(QUrl::fromNSURL(userActivity.webpageURL));