| Flutter iOS Embedder |

FlutterSceneDelegate.m
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterSceneDelegate.h"
6
7 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
8 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate_Internal.h"
9 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterSharedApplication.h"
10
11 FLUTTER_ASSERT_ARC
12
13 @implementation FlutterSceneDelegate
14
15 - (void)scene:(UIScene*)scene
16 willConnectToSession:(UISceneSession*)session
17 options:(UISceneConnectionOptions*)connectionOptions {
18 NSObject<UIApplicationDelegate>* appDelegate = FlutterSharedApplication.application.delegate;
19 if (appDelegate.window.rootViewController) {
20 NSLog(@"WARNING - The UIApplicationDelegate is setting up the UIWindow and "
21 @"UIWindow.rootViewController at launch. This was deprecated after the "
22 @"UISceneDelegate adoption. Setup logic should be moved to a UISceneDelegate.");
23 // If this is not nil we are running into a case where someone is manually
24 // performing root view controller setup in the UIApplicationDelegate.
25 UIWindowScene* windowScene = (UIWindowScene*)scene;
26 self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
27 self.window.rootViewController = appDelegate.window.rootViewController;
28 appDelegate.window = self.window;
29 [self.window makeKeyAndVisible];
30 }
31 }
32
33 - (void)windowScene:(UIWindowScene*)windowScene
34 performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
35 completionHandler:(void (^)(BOOL succeeded))completionHandler {
36 id appDelegate = FlutterSharedApplication.application.delegate;
37 if ([appDelegate respondsToSelector:@selector(lifeCycleDelegate)]) {
38 FlutterPluginAppLifeCycleDelegate* lifeCycleDelegate = [appDelegate lifeCycleDelegate];
39 [lifeCycleDelegate application:FlutterSharedApplication.application
40 performActionForShortcutItem:shortcutItem
41 completionHandler:completionHandler];
42 }
43 }
44
45 static NSDictionary<UIApplicationOpenURLOptionsKey, id>* ConvertOptions(
46 UISceneOpenURLOptions* options) {
47 if (@available(iOS 14.5, *)) {
48 return @{
49 UIApplicationOpenURLOptionsSourceApplicationKey : options.sourceApplication
50 ? options.sourceApplication
51 : [NSNull null],
52 UIApplicationOpenURLOptionsAnnotationKey : options.annotation ? options.annotation
53 : [NSNull null],
54 UIApplicationOpenURLOptionsOpenInPlaceKey : @(options.openInPlace),
55 UIApplicationOpenURLOptionsEventAttributionKey : options.eventAttribution
56 ? options.eventAttribution
57 : [NSNull null],
58 };
59 } else {
60 return @{
61 UIApplicationOpenURLOptionsSourceApplicationKey : options.sourceApplication
62 ? options.sourceApplication
63 : [NSNull null],
64 UIApplicationOpenURLOptionsAnnotationKey : options.annotation ? options.annotation
65 : [NSNull null],
66 UIApplicationOpenURLOptionsOpenInPlaceKey : @(options.openInPlace),
67 };
68 }
69 }
70
71 - (void)scene:(UIScene*)scene openURLContexts:(NSSet<UIOpenURLContext*>*)URLContexts {
72 id appDelegate = FlutterSharedApplication.application.delegate;
73 if ([appDelegate respondsToSelector:@selector(lifeCycleDelegate)]) {
74 FlutterPluginAppLifeCycleDelegate* lifeCycleDelegate = [appDelegate lifeCycleDelegate];
75 for (UIOpenURLContext* context in URLContexts) {
76 [lifeCycleDelegate application:FlutterSharedApplication.application
77 openURL:context.URL
78 options:ConvertOptions(context.options)];
79 };
80 }
81 }
82
83 @end
FlutterAppDelegate_Internal.h
FlutterMacros.h
FlutterSceneDelegate.h
FlutterSharedApplication.h
FlutterPluginAppLifeCycleDelegate
Definition: FlutterPluginAppLifeCycleDelegate.h:16
-[FlutterPluginAppLifeCycleDelegate application:performActionForShortcutItem:completionHandler:]
void application:performActionForShortcutItem:completionHandler:(UIApplication *application,[performActionForShortcutItem] UIApplicationShortcutItem *shortcutItem,[completionHandler] ios(9.0) API_AVAILABLE)
-[FlutterPluginAppLifeCycleDelegate application:openURL:options:]
BOOL application:openURL:options:(UIApplication *application,[openURL] NSURL *url,[options] NSDictionary< UIApplicationOpenURLOptionsKey, id > *options)
Definition: FlutterPluginAppLifeCycleDelegate.mm:318
FlutterSceneDelegate
Definition: FlutterSceneDelegate.h:19
FlutterSharedApplication
Definition: FlutterSharedApplication.h:11
FlutterSharedApplication::application
UIApplication * application
Definition: FlutterSharedApplication.h:25
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13