7 #import "flutter/shell/platform/darwin/common/InternalFlutterSwiftCommon/InternalFlutterSwiftCommon.h"
34 - (instancetype)init {
35 if (
self = [super 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]) {
153 return [
self handleOpenURL:url options:options relayToSystemIfUnhandled:NO];
157 - (BOOL)handleOpenURL:(NSURL*)url
158 options:(NSDictionary<UIApplicationOpenURLOptionsKey,
id>*)options
159 relayToSystemIfUnhandled:(BOOL)throwBack {
161 if (flutterApplication == nil) {
169 if (flutterViewController) {
170 [flutterViewController.engine sendDeepLinkToFramework:url
171 completionHandler:^(BOOL success) {
172 if (!success && throwBack) {
174 [flutterApplication openURL:url
176 completionHandler:nil];
180 [FlutterLogger logError:@"Attempting to open an URL without a Flutter RootViewController."];
186 - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url {
187 return [
self.lifeCycleDelegate application:application handleOpenURL:url];
190 - (BOOL)application:(UIApplication*)application
192 sourceApplication:(NSString*)sourceApplication
193 annotation:(
id)annotation {
194 return [
self.lifeCycleDelegate application:application
196 sourceApplication:sourceApplication
197 annotation:annotation];
200 - (void)application:(UIApplication*)application
201 performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
202 completionHandler:(
void (^)(BOOL succeeded))completionHandler {
203 [
self.lifeCycleDelegate application:application
204 performActionForShortcutItem:shortcutItem
205 completionHandler:completionHandler];
208 - (void)application:(UIApplication*)application
209 handleEventsForBackgroundURLSession:(nonnull NSString*)identifier
210 completionHandler:(nonnull
void (^)())completionHandler {
211 [
self.lifeCycleDelegate application:application
212 handleEventsForBackgroundURLSession:identifier
213 completionHandler:completionHandler];
217 - (BOOL)application:(UIApplication*)application
218 continueUserActivity:(NSUserActivity*)userActivity
219 restorationHandler:(
void (^)(NSArray<
id<UIUserActivityRestoring>>* __nullable
220 restorableObjects))restorationHandler {
222 continueUserActivity:userActivity
223 restorationHandler:restorationHandler]) {
227 return [
self handleOpenURL:userActivity.webpageURL options:@{} relayToSystemIfUnhandled:YES];
230 #pragma mark - FlutterPluginRegistry methods. All delegating to the rootViewController
233 if (_weakRegistrant) {
234 return _weakRegistrant;
236 if (_strongRegistrant) {
237 return _strongRegistrant;
245 _strongRegistrant = nil;
247 _weakRegistrant = nil;
254 if (flutterRootViewController) {
255 return [[flutterRootViewController
pluginRegistry] registrarForPlugin:pluginKey];
257 return [
self.launchEngine.engine registrarForPlugin:pluginKey];
260 - (BOOL)hasPlugin:(NSString*)pluginKey {
262 if (flutterRootViewController) {
263 return [[flutterRootViewController
pluginRegistry] hasPlugin:pluginKey];
265 return [
self.launchEngine.engine hasPlugin:pluginKey];
268 - (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey {
270 if (flutterRootViewController) {
271 return [[flutterRootViewController
pluginRegistry] valuePublishedByPlugin:pluginKey];
273 return [
self.launchEngine.engine valuePublishedByPlugin:pluginKey];
276 #pragma mark - Selectors handling
279 [
self.lifeCycleDelegate addDelegate:delegate];
282 #pragma mark - UIApplicationDelegate method dynamic implementation
284 - (BOOL)respondsToSelector:(
SEL)selector {
286 return [
self delegateRespondsSelectorToPlugins:selector];
288 return [
super respondsToSelector:selector];
291 - (BOOL)delegateRespondsSelectorToPlugins:(
SEL)selector {
293 return [
self.lifeCycleDelegate respondsToSelector:selector];
299 - (id)forwardingTargetForSelector:(
SEL)aSelector {
301 [
self logCapabilityConfigurationWarningIfNeeded:aSelector];
302 return self.lifeCycleDelegate;
304 return [
super forwardingTargetForSelector:aSelector];
311 - (void)logCapabilityConfigurationWarningIfNeeded:(
SEL)selector {
312 NSArray* backgroundModesArray =
313 [[NSBundle mainBundle] objectForInfoDictionaryKey:kUIBackgroundMode];
314 NSSet* backgroundModesSet = [[NSSet alloc] initWithArray:backgroundModesArray];
315 if (selector ==
@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:)) {
318 @"You've implemented -[<UIApplicationDelegate> "
319 @"application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need "
320 @"to add \"remote-notification\
" to the list of your supported UIBackgroundModes in your "
323 }
else if (selector ==
@selector(application:performFetchWithCompletionHandler:)) {
325 NSLog(
@"You've implemented -[<UIApplicationDelegate> "
326 @"application:performFetchWithCompletionHandler:], but you still need to add \"fetch\
" "
327 @"to the list of your supported UIBackgroundModes in your Info.plist.");
332 #pragma mark - State Restoration
334 - (BOOL)application:(UIApplication*)application shouldSaveApplicationState:(NSCoder*)coder {
335 [coder encodeInt64:FlutterSharedApplication.lastAppModificationTime
336 forKey:kRestorationStateAppModificationKey];
340 - (BOOL)application:(UIApplication*)application shouldRestoreApplicationState:(NSCoder*)coder {
341 int64_t stateDate = [coder decodeInt64ForKey:kRestorationStateAppModificationKey];
345 - (BOOL)application:(UIApplication*)application shouldSaveSecureApplicationState:(NSCoder*)coder {
346 [coder encodeInt64:FlutterSharedApplication.lastAppModificationTime
347 forKey:kRestorationStateAppModificationKey];
351 - (BOOL)application:(UIApplication*)application
352 shouldRestoreSecureApplicationState:(NSCoder*)coder {
353 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()