Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,43 @@ - (BOOL)application:(UIApplication*)application
continueUserActivity:(NSUserActivity*)userActivity
restorationHandler:(void (^)(NSArray* __nullable restorableObjects))restorationHandler {
#endif
return [_lifeCycleDelegate application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
if ([_lifeCycleDelegate application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler]) {
return YES;
} else if (userActivity.activityType == NSUserActivityTypeBrowsingWeb) {
return NO;
} else {
NSURLComponents* components = [NSURLComponents componentsWithURL:userActivity.webpageURL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get the query and path off the userActivity.webpageURL URL if it's nonnull instead of creating a NSURLComponents?

resolvingAgainstBaseURL:YES];

if (components == nil or components.path == nil) {
return NO;
}
FlutterViewController* flutterViewController = [self rootFlutterViewController];
if (flutterViewController) {
[flutterViewController.engine
waitForFirstFrame:3.0
callback:^(BOOL didTimeout) {
if (didTimeout) {
FML_LOG(ERROR) << "Timeout waiting for the first frame when launching a "
"universal link.";
} else {
NSString* pathAndQuery = components.path;
if (components.query != nil and [components.query length] != 0) {
pathAndQuery =
[NSString stringWithFormat:@"%@?%@", pathAndQuery, components.query];
}
[flutterViewController.engine.navigationChannel invokeMethod:@"pushRoute"
arguments:pathAndQuery];
}
}];
return YES;
} else {
FML_LOG(ERROR) << "Attempting to open a universal link without a Flutter RootViewController.";
return NO;
}
}
}

#pragma mark - FlutterPluginRegistry methods. All delegating to the rootViewController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,28 @@ - (void)skip_testLaunchUrl {
OCMVerify([navigationChannel invokeMethod:@"pushRoute" arguments:@"/custom/route?query=test"]);
}

- (void)skip_testLaunchUniversalLink {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the unit test 😄

FlutterAppDelegate* appDelegate = [[FlutterAppDelegate alloc] init];
FlutterViewController* viewController = OCMClassMock([FlutterViewController class]);
FlutterEngine* engine = OCMClassMock([FlutterEngine class]);
FlutterMethodChannel* navigationChannel = OCMClassMock([FlutterMethodChannel class]);
OCMStub([engine navigationChannel]).andReturn(navigationChannel);
OCMStub([viewController engine]).andReturn(engine);
OCMStub([engine waitForFirstFrame:3.0 callback:([OCMArg invokeBlockWithArgs:@(NO), nil])]);
appDelegate.rootFlutterViewControllerGetter = ^{
return viewController;
};
NSURL* url = [NSURL URLWithString:@"http://myApp/custom/route?query=test"];
NSUserActivity* userActivity =
[[NSUserActivity alloc] initWithActivityType:NSUserActivityTypeBrowsingWeb];
userActivity.webpageURL = url;
BOOL result = [appDelegate
application:[UIApplication sharedApplication]
continueUserActivity:userActivity
restorationHandler:^(NSArray<id<UIUserActivityRestoring>>* __nullable restorableObjects){
}];
XCTAssertTrue(result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something but shouldn't this be false since it falls into the else if (userActivity.activityType == NSUserActivityTypeBrowsingWeb) statement?

OCMVerify([navigationChannel invokeMethod:@"pushRoute" arguments:@"/custom/route?query=test"]);
}

@end