7 #import "flutter/shell/platform/darwin/common/InternalFlutterSwiftCommon/InternalFlutterSwiftCommon.h"
8 #import "flutter/shell/platform/darwin/ios/InternalFlutterSwift/InternalFlutterSwift.h"
29 @property(nonatomic, strong) FlutterLaunchEngine* launchEngine;
34 - (instancetype)init {
35 if (
self = [super init]) {
37 _launchEngine = [[FlutterLaunchEngine alloc] init];
43 return [
self.launchEngine takeEngine];
46 - (BOOL)application:(UIApplication*)application
47 willFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
48 return [
self.lifeCycleDelegate application:application
49 willFinishLaunchingWithOptions:launchOptions];
52 - (BOOL)application:(UIApplication*)application
53 didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
54 return [
self.lifeCycleDelegate application:application
55 didFinishLaunchingWithOptions:launchOptions];
61 if (_rootFlutterViewControllerGetter != nil) {
62 return _rootFlutterViewControllerGetter();
64 UIViewController* rootViewController = _window.rootViewController;
72 - (void)applicationDidEnterBackground:(UIApplication*)application {
76 - (void)applicationWillEnterForeground:(UIApplication*)application {
80 - (void)applicationWillResignActive:(UIApplication*)application {
84 - (void)applicationDidBecomeActive:(UIApplication*)application {
88 - (void)applicationWillTerminate:(UIApplication*)application {
91 #pragma GCC diagnostic push
92 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
93 - (void)application:(UIApplication*)application
94 didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings {
95 [
self.lifeCycleDelegate application:application
96 didRegisterUserNotificationSettings:notificationSettings];
98 #pragma GCC diagnostic pop
100 - (void)application:(UIApplication*)application
101 didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
102 [
self.lifeCycleDelegate application:application
103 didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
106 - (void)application:(UIApplication*)application
107 didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
108 [
self.lifeCycleDelegate application:application
109 didFailToRegisterForRemoteNotificationsWithError:error];
112 #pragma GCC diagnostic push
113 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
114 - (void)application:(UIApplication*)application
115 didReceiveLocalNotification:(UILocalNotification*)notification {
116 [
self.lifeCycleDelegate application:application didReceiveLocalNotification:notification];
118 #pragma GCC diagnostic pop
120 - (void)userNotificationCenter:(UNUserNotificationCenter*)center
121 willPresentNotification:(UNNotification*)notification
122 withCompletionHandler:
123 (
void (^)(UNNotificationPresentationOptions options))completionHandler {
125 [
self.lifeCycleDelegate userNotificationCenter:center
126 willPresentNotification:notification
127 withCompletionHandler:completionHandler];
134 - (void)userNotificationCenter:(UNUserNotificationCenter*)center
135 didReceiveNotificationResponse:(UNNotificationResponse*)response
136 withCompletionHandler:(
void (^)(
void))completionHandler {
138 [
self.lifeCycleDelegate userNotificationCenter:center
139 didReceiveNotificationResponse:response
140 withCompletionHandler:completionHandler];
145 - (BOOL)application:(UIApplication*)application
147 options:(NSDictionary<UIApplicationOpenURLOptionsKey,
id>*)options {
148 if ([
self.
lifeCycleDelegate application:application openURL:url options:options]) {
152 return [
self handleOpenURL:url options:options];
156 - (BOOL)handleOpenURL:(NSURL*)url
157 options:(NSDictionary<UIApplicationOpenURLOptionsKey,
id>*)options {
159 if (flutterApplication == nil) {
167 if (flutterViewController) {
168 [flutterViewController.engine sendDeepLinkToFramework:url
169 completionHandler:^(BOOL success){
173 [FlutterLogger logError:@"Attempting to open an URL without a Flutter RootViewController."];
179 - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url {
180 return [
self.lifeCycleDelegate application:application handleOpenURL:url];
183 - (BOOL)application:(UIApplication*)application
185 sourceApplication:(NSString*)sourceApplication
186 annotation:(
id)annotation {
187 return [
self.lifeCycleDelegate application:application
189 sourceApplication:sourceApplication
190 annotation:annotation];
193 - (void)application:(UIApplication*)application
194 performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
195 completionHandler:(
void (^)(BOOL succeeded))completionHandler {
196 [
self.lifeCycleDelegate application:application
197 performActionForShortcutItem:shortcutItem
198 completionHandler:completionHandler];
201 - (void)application:(UIApplication*)application
202 handleEventsForBackgroundURLSession:(nonnull NSString*)identifier
203 completionHandler:(nonnull
void (^)())completionHandler {
204 [
self.lifeCycleDelegate application:application
205 handleEventsForBackgroundURLSession:identifier
206 completionHandler:completionHandler];
210 - (BOOL)application:(UIApplication*)application
211 continueUserActivity:(NSUserActivity*)userActivity
212 restorationHandler:(
void (^)(NSArray<
id<UIUserActivityRestoring>>* __nullable
213 restorableObjects))restorationHandler {
215 continueUserActivity:userActivity
216 restorationHandler:restorationHandler]) {
220 return [
self handleOpenURL:userActivity.webpageURL options:@{}];
223 #pragma mark - FlutterPluginRegistry methods. All delegating to the rootViewController
226 if (_weakRegistrant) {
227 return _weakRegistrant;
229 if (_strongRegistrant) {
230 return _strongRegistrant;
238 _strongRegistrant = nil;
240 _weakRegistrant = nil;
247 if (flutterRootViewController) {
248 return [[flutterRootViewController
pluginRegistry] registrarForPlugin:pluginKey];
250 return [[
self.launchEngine acquireEngine] registrarForPlugin:pluginKey];
253 - (BOOL)hasPlugin:(NSString*)pluginKey {
255 if (flutterRootViewController) {
256 return [[flutterRootViewController
pluginRegistry] hasPlugin:pluginKey];
258 return [[
self.launchEngine acquireEngine] hasPlugin:pluginKey];
261 - (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey {
263 if (flutterRootViewController) {
264 return [[flutterRootViewController
pluginRegistry] valuePublishedByPlugin:pluginKey];
266 return [[
self.launchEngine acquireEngine] valuePublishedByPlugin:pluginKey];
269 #pragma mark - Selectors handling
272 [
self.lifeCycleDelegate addDelegate:delegate];
275 #pragma mark - UIApplicationDelegate method dynamic implementation
277 - (BOOL)respondsToSelector:(
SEL)selector {
279 return [
self delegateRespondsSelectorToPlugins:selector];
281 return [
super respondsToSelector:selector];
284 - (BOOL)delegateRespondsSelectorToPlugins:(
SEL)selector {
286 return [
self.lifeCycleDelegate respondsToSelector:selector];
292 - (id)forwardingTargetForSelector:(
SEL)aSelector {
294 [
self logCapabilityConfigurationWarningIfNeeded:aSelector];
295 return self.lifeCycleDelegate;
297 return [
super forwardingTargetForSelector:aSelector];
304 - (void)logCapabilityConfigurationWarningIfNeeded:(
SEL)selector {
305 NSArray* backgroundModesArray =
306 [[NSBundle mainBundle] objectForInfoDictionaryKey:kUIBackgroundMode];
307 NSSet* backgroundModesSet = [[NSSet alloc] initWithArray:backgroundModesArray];
308 if (selector ==
@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:)) {
311 @"You've implemented -[<UIApplicationDelegate> "
312 @"application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need "
313 @"to add \"remote-notification\
" to the list of your supported UIBackgroundModes in your "
316 }
else if (selector ==
@selector(application:performFetchWithCompletionHandler:)) {
318 NSLog(
@"You've implemented -[<UIApplicationDelegate> "
319 @"application:performFetchWithCompletionHandler:], but you still need to add \"fetch\
" "
320 @"to the list of your supported UIBackgroundModes in your Info.plist.");
325 #pragma mark - State Restoration
327 - (BOOL)application:(UIApplication*)application shouldSaveApplicationState:(NSCoder*)coder {
328 [coder encodeInt64:FlutterSharedApplication.lastAppModificationTime
329 forKey:kRestorationStateAppModificationKey];
333 - (BOOL)application:(UIApplication*)application shouldRestoreApplicationState:(NSCoder*)coder {
334 int64_t stateDate = [coder decodeInt64ForKey:kRestorationStateAppModificationKey];
338 - (BOOL)application:(UIApplication*)application shouldSaveSecureApplicationState:(NSCoder*)coder {
339 [coder encodeInt64:FlutterSharedApplication.lastAppModificationTime
340 forKey:kRestorationStateAppModificationKey];
344 - (BOOL)application:(UIApplication*)application
345 shouldRestoreSecureApplicationState:(NSCoder*)coder {
346 int64_t stateDate = [coder decodeInt64ForKey:kRestorationStateAppModificationKey];
static NSString *const kRemoteNotificationCapabitiliy
static FLUTTER_ASSERT_ARC NSString *const kUIBackgroundMode
static NSString *const kBackgroundFetchCapatibility
__weak NSObject< FlutterPluginRegistrant > * _weakRegistrant
NSObject< FlutterPluginRegistrant > * _strongRegistrant
FlutterPluginAppLifeCycleDelegate * lifeCycleDelegate
NSObject< FlutterPluginRegistrant > * pluginRegistrant
UIApplication * application
int64_t lastAppModificationTime
BOOL isFlutterDeepLinkingEnabled()
id< FlutterPluginRegistry > pluginRegistry()