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

Commit 17c1773

Browse files
committed
Handle iOS Universal Links
1 parent c0dc2c0 commit 17c1773

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

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

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,43 @@ - (BOOL)application:(UIApplication*)application
227227
continueUserActivity:(NSUserActivity*)userActivity
228228
restorationHandler:(void (^)(NSArray* __nullable restorableObjects))restorationHandler {
229229
#endif
230-
return [_lifeCycleDelegate application:application
231-
continueUserActivity:userActivity
232-
restorationHandler:restorationHandler];
230+
if ([_lifeCycleDelegate application:application
231+
continueUserActivity:userActivity
232+
restorationHandler:restorationHandler]) {
233+
return YES;
234+
}
235+
else if (userActivity.activityType == NSUserActivityTypeBrowsingWeb) {
236+
return NO;
237+
} else {
238+
NSURLComponents* components = [NSURLComponents componentsWithURL:userActivity.webpageURL resolvingAgainstBaseURL:YES];
239+
240+
if (components == nil or components.path == nil){
241+
return NO;
242+
}
243+
FlutterViewController* flutterViewController = [self rootFlutterViewController];
244+
if (flutterViewController) {
245+
[flutterViewController.engine
246+
waitForFirstFrame:3.0
247+
callback:^(BOOL didTimeout) {
248+
if (didTimeout) {
249+
FML_LOG(ERROR)
250+
<< "Timeout waiting for the first frame when launching a universal link.";
251+
} else {
252+
NSString* pathAndQuery = components.path;
253+
if (components.query != nil and [components.query length] != 0) {
254+
pathAndQuery =
255+
[NSString stringWithFormat:@"%@?%@", pathAndQuery, components.query];
256+
}
257+
[flutterViewController.engine.navigationChannel invokeMethod:@"pushRoute"
258+
arguments:pathAndQuery];
259+
}
260+
}];
261+
return YES;
262+
} else {
263+
FML_LOG(ERROR) << "Attempting to open a universal link without a Flutter RootViewController.";
264+
return NO;
265+
}
266+
}
233267
}
234268

235269
#pragma mark - FlutterPluginRegistry methods. All delegating to the rootViewController

0 commit comments

Comments
 (0)