15#include <qpa/qplatformintegration.h>
17#include <QtCore/QtCore>
19#include <QtCore/private/qdarwinsecurityscopedfileengine_p.h>
21@interface QIOSWindowSceneDelegate : NSObject<UIWindowSceneDelegate>
22@property (nullable, nonatomic, strong) UIWindow *window;
25@implementation QIOSApplicationDelegate
27- (UISceneConfiguration *)application:(UIApplication *)application
28 configurationForConnectingSceneSession:(UISceneSession *)session
29 options:(UISceneConnectionOptions *)options
31 qCDebug(lcQpaWindowScene) <<
"Configuring scene for" << session <<
"with options" << options;
33 auto *sceneConfig = session.configuration;
35 if ([sceneConfig.role hasPrefix:@
"CPTemplateApplication"]) {
36 qCDebug(lcQpaWindowScene) <<
"Not touching CarPlay scene with role" << sceneConfig.role
37 <<
"and existing delegate class" << sceneConfig.delegateClass;
41 sceneConfig.delegateClass = QIOSWindowSceneDelegate.
class;
49@implementation QIOSWindowSceneDelegate
51- (
void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions
53 qCDebug(lcQpaWindowScene) <<
"Connecting" << scene <<
"to" << session;
56 const auto handleConnectionOptions = qScopeGuard([&]{
57 if (connectionOptions.URLContexts.count > 0)
58 [self scene:scene openURLContexts:connectionOptions.URLContexts];
60 for (NSUserActivity *activity in connectionOptions.userActivities)
61 [self scene:scene continueUserActivity:activity];
64#if defined(Q_OS_VISIONOS)
68 if ([scene.session.role isEqualToString:@
"CPSceneSessionRoleImmersiveSpaceApplication"]) {
69 qCDebug(lcQpaWindowScene) <<
"Skipping UIWindow creation for immersive scene";
74 if (![scene isKindOfClass:UIWindowScene.
class]) {
75 qCWarning(lcQpaWindowScene) <<
"Unexpectedly encountered non-window scene";
79 UIWindowScene *windowScene =
static_cast<UIWindowScene*>(scene);
81 QUIWindow *window = [[QUIWindow alloc] initWithWindowScene:windowScene];
82 window.rootViewController = [[[QIOSViewController alloc] initWithWindow:window] autorelease];
84 self.window = [window autorelease];
87- (
void)windowScene:(UIWindowScene *)windowScene
88 didUpdateCoordinateSpace:(id<UICoordinateSpace>)previousCoordinateSpace
89 interfaceOrientation:(UIInterfaceOrientation)previousInterfaceOrientation
90 traitCollection:(UITraitCollection *)previousTraitCollection
92 qCDebug(lcQpaWindowScene) <<
"Scene" << windowScene <<
"did update properties";
96 Q_ASSERT([self.window isKindOfClass:QUIWindow.
class]);
97 auto *viewController =
static_cast<QIOSViewController*>(self.window.rootViewController);
98 [viewController updatePlatformScreen];
101- (
void)sceneDidDisconnect:(UIScene *)scene
103 qCDebug(lcQpaWindowScene) <<
"Disconnecting" << scene;
107- (
void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts
109 qCDebug(lcQpaWindowScene) <<
"Handling openURLContexts for scene" << scene;
111 QIOSIntegration *iosIntegration = QIOSIntegration::instance();
112 Q_ASSERT(iosIntegration);
114 QIOSServices *iosServices =
static_cast<QIOSServices *>(iosIntegration->services());
116 for (UIOpenURLContext *urlContext in URLContexts) {
117 QUrl url = qt_apple_urlFromPossiblySecurityScopedURL(urlContext.URL);
118 if (url.isLocalFile())
119 QWindowSystemInterface::handleFileOpenEvent(url);
121 iosServices->handleUrl(url);
125- (
void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity
127 qCDebug(lcQpaWindowScene) <<
"Handling user activity for scene" << scene;
129 if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
130 QIOSIntegration *iosIntegration = QIOSIntegration::instance();
131 Q_ASSERT(iosIntegration);
133 QIOSServices *iosServices =
static_cast<QIOSServices *>(iosIntegration->services());
134 iosServices->handleUrl(QUrl::fromNSURL(userActivity.webpageURL));