7 #import "flutter/fml/logging.h"
27 - (instancetype)init {
28 if (
self = [super init]) {
35 [_lifeCycleDelegate release];
36 [_rootFlutterViewControllerGetter release];
41 - (BOOL)application:(UIApplication*)application
42 willFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
43 return [_lifeCycleDelegate application:application willFinishLaunchingWithOptions:launchOptions];
46 - (BOOL)application:(UIApplication*)application
47 didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
48 return [_lifeCycleDelegate application:application didFinishLaunchingWithOptions:launchOptions];
54 if (_rootFlutterViewControllerGetter != nil) {
55 return _rootFlutterViewControllerGetter();
57 UIViewController* rootViewController = _window.rootViewController;
65 - (void)applicationDidEnterBackground:(UIApplication*)application {
69 - (void)applicationWillEnterForeground:(UIApplication*)application {
73 - (void)applicationWillResignActive:(UIApplication*)application {
77 - (void)applicationDidBecomeActive:(UIApplication*)application {
81 - (void)applicationWillTerminate:(UIApplication*)application {
84 #pragma GCC diagnostic push
85 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
86 - (void)application:(UIApplication*)application
87 didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings {
88 [_lifeCycleDelegate application:application
89 didRegisterUserNotificationSettings:notificationSettings];
91 #pragma GCC diagnostic pop
93 - (void)application:(UIApplication*)application
94 didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
95 [_lifeCycleDelegate application:application
96 didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
99 - (void)application:(UIApplication*)application
100 didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
101 [_lifeCycleDelegate application:application
102 didFailToRegisterForRemoteNotificationsWithError:error];
105 #pragma GCC diagnostic push
106 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
107 - (void)application:(UIApplication*)application
108 didReceiveLocalNotification:(UILocalNotification*)notification {
109 [_lifeCycleDelegate application:application didReceiveLocalNotification:notification];
111 #pragma GCC diagnostic pop
113 - (void)userNotificationCenter:(UNUserNotificationCenter*)center
114 willPresentNotification:(UNNotification*)notification
115 withCompletionHandler:
116 (
void (^)(UNNotificationPresentationOptions options))completionHandler {
117 if ([_lifeCycleDelegate respondsToSelector:_cmd]) {
118 [_lifeCycleDelegate userNotificationCenter:center
119 willPresentNotification:notification
120 withCompletionHandler:completionHandler];
127 - (void)userNotificationCenter:(UNUserNotificationCenter*)center
128 didReceiveNotificationResponse:(UNNotificationResponse*)response
129 withCompletionHandler:(
void (^)(
void))completionHandler {
130 if ([_lifeCycleDelegate respondsToSelector:_cmd]) {
131 [_lifeCycleDelegate userNotificationCenter:center
132 didReceiveNotificationResponse:response
133 withCompletionHandler:completionHandler];
137 - (BOOL)openURL:(NSURL*)url {
138 NSNumber* isDeepLinkingEnabled =
139 [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"];
140 if (!isDeepLinkingEnabled.boolValue) {
145 if (flutterViewController) {
146 [flutterViewController.engine
147 waitForFirstFrame:3.0
148 callback:^(BOOL didTimeout) {
151 << "Timeout waiting for the first frame when launching an URL.";
153 [flutterViewController.engine.navigationChannel
154 invokeMethod:@"pushRouteInformation"
156 @"location" : url.absoluteString ?: [NSNull null],
162 FML_LOG(ERROR) <<
"Attempting to open an URL without a Flutter RootViewController.";
168 - (BOOL)application:(UIApplication*)application
170 options:(NSDictionary<UIApplicationOpenURLOptionsKey,
id>*)options {
171 if ([_lifeCycleDelegate application:application openURL:url options:options]) {
174 return [
self openURL:url];
177 - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url {
178 return [_lifeCycleDelegate application:application handleOpenURL:url];
181 - (BOOL)application:(UIApplication*)application
183 sourceApplication:(NSString*)sourceApplication
184 annotation:(
id)annotation {
185 return [_lifeCycleDelegate application:application
187 sourceApplication:sourceApplication
188 annotation:annotation];
191 - (void)application:(UIApplication*)application
192 performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
193 completionHandler:(
void (^)(BOOL succeeded))completionHandler {
194 [_lifeCycleDelegate application:application
195 performActionForShortcutItem:shortcutItem
196 completionHandler:completionHandler];
199 - (void)application:(UIApplication*)application
200 handleEventsForBackgroundURLSession:(nonnull NSString*)identifier
201 completionHandler:(nonnull
void (^)())completionHandler {
202 [_lifeCycleDelegate application:application
203 handleEventsForBackgroundURLSession:identifier
204 completionHandler:completionHandler];
207 - (BOOL)application:(UIApplication*)application
208 continueUserActivity:(NSUserActivity*)userActivity
209 restorationHandler:(
void (^)(NSArray<
id<UIUserActivityRestoring>>* __nullable
210 restorableObjects))restorationHandler {
211 if ([_lifeCycleDelegate application:application
212 continueUserActivity:userActivity
213 restorationHandler:restorationHandler]) {
216 return [
self openURL:userActivity.webpageURL];
219 #pragma mark - FlutterPluginRegistry methods. All delegating to the rootViewController
223 if (flutterRootViewController) {
224 return [[flutterRootViewController
pluginRegistry] registrarForPlugin:pluginKey];
229 - (BOOL)hasPlugin:(NSString*)pluginKey {
231 if (flutterRootViewController) {
232 return [[flutterRootViewController
pluginRegistry] hasPlugin:pluginKey];
237 - (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey {
239 if (flutterRootViewController) {
240 return [[flutterRootViewController
pluginRegistry] valuePublishedByPlugin:pluginKey];
245 #pragma mark - Selectors handling
248 [_lifeCycleDelegate addDelegate:delegate];
251 #pragma mark - UIApplicationDelegate method dynamic implementation
253 - (BOOL)respondsToSelector:(
SEL)selector {
254 if ([_lifeCycleDelegate isSelectorAddedDynamically:selector]) {
255 return [
self delegateRespondsSelectorToPlugins:selector];
257 return [
super respondsToSelector:selector];
260 - (BOOL)delegateRespondsSelectorToPlugins:(
SEL)selector {
261 if ([_lifeCycleDelegate hasPluginThatRespondsToSelector:selector]) {
262 return [_lifeCycleDelegate respondsToSelector:selector];
268 - (id)forwardingTargetForSelector:(
SEL)aSelector {
269 if ([_lifeCycleDelegate isSelectorAddedDynamically:aSelector]) {
270 [
self logCapabilityConfigurationWarningIfNeeded:aSelector];
271 return _lifeCycleDelegate;
273 return [
super forwardingTargetForSelector:aSelector];
280 - (void)logCapabilityConfigurationWarningIfNeeded:(
SEL)selector {
281 NSArray* backgroundModesArray =
282 [[NSBundle mainBundle] objectForInfoDictionaryKey:kUIBackgroundMode];
283 NSSet* backgroundModesSet = [[[NSSet alloc] initWithArray:backgroundModesArray] autorelease];
284 if (selector ==
@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:)) {
287 @"You've implemented -[<UIApplicationDelegate> "
288 @"application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need "
289 @"to add \"remote-notification\
" to the list of your supported UIBackgroundModes in your "
292 }
else if (selector ==
@selector(application:performFetchWithCompletionHandler:)) {
294 NSLog(
@"You've implemented -[<UIApplicationDelegate> "
295 @"application:performFetchWithCompletionHandler:], but you still need to add \"fetch\
" "
296 @"to the list of your supported UIBackgroundModes in your Info.plist.");
301 #pragma mark - State Restoration
303 - (BOOL)application:(UIApplication*)application shouldSaveApplicationState:(NSCoder*)coder {
304 [coder encodeInt64:self.lastAppModificationTime forKey:kRestorationStateAppModificationKey];
308 - (BOOL)application:(UIApplication*)application shouldRestoreApplicationState:(NSCoder*)coder {
309 int64_t stateDate = [coder decodeInt64ForKey:kRestorationStateAppModificationKey];
310 return self.lastAppModificationTime == stateDate;
313 - (BOOL)application:(UIApplication*)application shouldSaveSecureApplicationState:(NSCoder*)coder {
314 [coder encodeInt64:self.lastAppModificationTime forKey:kRestorationStateAppModificationKey];
318 - (BOOL)application:(UIApplication*)application
319 shouldRestoreSecureApplicationState:(NSCoder*)coder {
320 int64_t stateDate = [coder decodeInt64ForKey:kRestorationStateAppModificationKey];
321 return self.lastAppModificationTime == stateDate;
324 - (int64_t)lastAppModificationTime {
326 NSError* error = nil;
327 [[[NSBundle mainBundle] executableURL] getResourceValue:&fileDate
328 forKey:NSURLContentModificationDateKey
330 NSAssert(error == nil,
@"Cannot obtain modification date of main bundle: %@", error);
331 return [fileDate timeIntervalSince1970];