Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f800400

Browse files
committed
Started passing URLs as routes down to the Framework.
1 parent af5717e commit f800400

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h"
66

7-
#include "flutter/fml/logging.h"
7+
#import "flutter/fml/logging.h"
88
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h"
99
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
1010
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate_internal.h"
11+
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
1112

1213
static NSString* kUIBackgroundMode = @"UIBackgroundModes";
1314
static NSString* kRemoteNotificationCapabitiliy = @"remote-notification";
@@ -124,7 +125,28 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center
124125
- (BOOL)application:(UIApplication*)application
125126
openURL:(NSURL*)url
126127
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id>*)options {
127-
return [_lifeCycleDelegate application:application openURL:url options:options];
128+
if ([_lifeCycleDelegate application:application openURL:url options:options]) {
129+
return YES;
130+
} else {
131+
UIViewController* rootViewController = _window.rootViewController;
132+
if ([rootViewController isKindOfClass:[FlutterViewController class]]) {
133+
FlutterViewController* flutterViewController = (FlutterViewController*)rootViewController;
134+
[flutterViewController.engine
135+
waitForFirstFrame:3.0
136+
callback:^(BOOL didTimeout) {
137+
if (didTimeout) {
138+
FML_LOG(ERROR)
139+
<< "Timeout waiting for the first frame when launching an URL.";
140+
} else {
141+
[flutterViewController.engine.navigationChannel invokeMethod:@"pushRoute"
142+
arguments:url.path];
143+
}
144+
}];
145+
} else {
146+
FML_LOG(ERROR) << "Attempting to open an URL without a Flutter RootViewController.";
147+
}
148+
return YES;
149+
}
128150
}
129151

130152
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url {

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,18 @@ - (void)onLocaleUpdated:(NSNotification*)notification {
869869
[self.localizationChannel invokeMethod:@"setLocale" arguments:localeData];
870870
}
871871

872+
- (void)waitForFirstFrame:(NSTimeInterval)timeout
873+
callback:(void(^_Nonnull)(BOOL didTimeout))callback {
874+
dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0);
875+
dispatch_async(queue, ^{
876+
fml::TimeDelta waitTime = fml::TimeDelta::FromMilliseconds(timeout * 1000);
877+
BOOL didTimeout = self.shell.WaitForFirstFrame(waitTime).code() == fml::StatusCode::kDeadlineExceeded;
878+
dispatch_async(dispatch_get_main_queue(), ^{
879+
callback(didTimeout);
880+
});
881+
});
882+
}
883+
872884
@end
873885

874886
@implementation FlutterEngineRegistrar {

shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
- (void)notifyLowMemory;
4949
- (flutter::PlatformViewIOS*)iosPlatformView;
5050

51+
- (void)waitForFirstFrame:(NSTimeInterval)timeout
52+
callback:(void(^)(BOOL didTimeout))callback;
5153
@end
5254

5355
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERENGINE_INTERNAL_H_

0 commit comments

Comments
 (0)