| Flutter iOS Embedder |

FlutterSceneDelegate.mm
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/Headers/FlutterSceneLifeCycle.h"
9 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate_Internal.h"
10 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterSceneLifeCycle_Internal.h"
11 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterSharedApplication.h"
12
13 FLUTTER_ASSERT_ARC
14
15 @interface FlutterSceneDelegate () <FlutterSceneLifeCycleProvider>
16 @end
17
18 @implementation FlutterSceneDelegate
19
20 @synthesize sceneLifeCycleDelegate = _sceneLifeCycleDelegate;
21
22 - (instancetype)init {
23 if (self = [super init]) {
24 _sceneLifeCycleDelegate = [[FlutterPluginSceneLifeCycleDelegate alloc] init];
25 }
26 return self;
27 }
28
29 #pragma mark - Connecting and disconnecting the scene
30
31 - (void)scene:(UIScene*)scene
32 willConnectToSession:(UISceneSession*)session
33 options:(UISceneConnectionOptions*)connectionOptions {
34 NSObject<UIApplicationDelegate>* appDelegate = FlutterSharedApplication.application.delegate;
35 if ([appDelegate respondsToSelector:@selector(window)] && appDelegate.window.rootViewController) {
36 NSLog(@"WARNING - The UIApplicationDelegate is setting up the UIWindow and "
37 @"UIWindow.rootViewController at launch. This was deprecated after the "
38 @"UISceneDelegate adoption. Setup logic should be moved to a UISceneDelegate.");
39 // If this is not nil we are running into a case where someone is manually
40 // performing root view controller setup in the UIApplicationDelegate.
41 UIWindowScene* windowScene = (UIWindowScene*)scene;
42 [self moveRootViewControllerFrom:appDelegate to:windowScene];
43 }
44 [self.sceneLifeCycleDelegate scene:scene willConnectToSession:session options:connectionOptions];
45 }
46
47 - (void)sceneDidDisconnect:(UIScene*)scene {
48 [self.sceneLifeCycleDelegate sceneDidDisconnect:scene];
49 }
50
51 #pragma mark - Transitioning to the foreground
52
53 - (void)sceneWillEnterForeground:(UIScene*)scene {
54 [self.sceneLifeCycleDelegate sceneWillEnterForeground:scene];
55 }
56
57 - (void)sceneDidBecomeActive:(UIScene*)scene {
58 [self.sceneLifeCycleDelegate sceneDidBecomeActive:scene];
59 }
60
61 #pragma mark - Transitioning to the background
62
63 - (void)sceneWillResignActive:(UIScene*)scene {
64 [self.sceneLifeCycleDelegate sceneWillResignActive:scene];
65 }
66
67 - (void)sceneDidEnterBackground:(UIScene*)scene {
68 [self.sceneLifeCycleDelegate sceneDidEnterBackground:scene];
69 }
70
71 #pragma mark - Opening URLs
72
73 - (void)scene:(UIScene*)scene openURLContexts:(NSSet<UIOpenURLContext*>*)URLContexts {
74 [self.sceneLifeCycleDelegate scene:scene openURLContexts:URLContexts];
75 }
76
77 #pragma mark - Continuing user activities
78
79 - (void)scene:(UIScene*)scene continueUserActivity:(NSUserActivity*)userActivity {
80 [self.sceneLifeCycleDelegate scene:scene continueUserActivity:userActivity];
81 }
82
83 #pragma mark - Saving the state of the scene
84
85 - (NSUserActivity*)stateRestorationActivityForScene:(UIScene*)scene {
86 return [self.sceneLifeCycleDelegate stateRestorationActivityForScene:scene];
87 }
88
89 - (void)scene:(UIScene*)scene
90 restoreInteractionStateWithUserActivity:(NSUserActivity*)stateRestorationActivity {
91 [self.sceneLifeCycleDelegate scene:scene
92 restoreInteractionStateWithUserActivity:stateRestorationActivity];
93 }
94
95 #pragma mark - Performing tasks
96
97 - (void)windowScene:(UIWindowScene*)windowScene
98 performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
99 completionHandler:(void (^)(BOOL succeeded))completionHandler {
100 [self.sceneLifeCycleDelegate windowScene:windowScene
101 performActionForShortcutItem:shortcutItem
102 completionHandler:completionHandler];
103 }
104
105 #pragma mark - Helpers
106
107 - (BOOL)registerSceneLifeCycleWithFlutterEngine:(FlutterEngine*)engine {
108 return [self.sceneLifeCycleDelegate registerSceneLifeCycleWithFlutterEngine:engine];
109 }
110
111 - (BOOL)unregisterSceneLifeCycleWithFlutterEngine:(FlutterEngine*)engine {
112 return [self.sceneLifeCycleDelegate unregisterSceneLifeCycleWithFlutterEngine:engine];
113 }
114
115 - (void)moveRootViewControllerFrom:(NSObject<UIApplicationDelegate>*)appDelegate
116 to:(UIWindowScene*)windowScene {
117 self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
118 self.window.rootViewController = appDelegate.window.rootViewController;
119 appDelegate.window = self.window;
120 [self.window makeKeyAndVisible];
121 }
122 @end
FlutterAppDelegate_Internal.h
FlutterMacros.h
FlutterSceneDelegate.h
FlutterSceneLifeCycle.h
FlutterSceneLifeCycle_Internal.h
FlutterSharedApplication.h
FlutterEngine
Definition: FlutterEngine.h:61
FlutterPluginSceneLifeCycleDelegate
Definition: FlutterSceneLifeCycle.h:149
FlutterSceneDelegate
Definition: FlutterSceneDelegate.h:21
FlutterSceneDelegate::window
FlutterSceneLifeCycleEngineRegistration UIWindow * window
Definition: FlutterSceneDelegate.h:22
FlutterSharedApplication
Definition: FlutterSharedApplication.h:13
FlutterSharedApplication::application
UIApplication * application
Definition: FlutterSharedApplication.h:27
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13
FlutterSceneLifeCycleProvider-p
Definition: FlutterSceneLifeCycle.h:214