This happens because the iOS SDK routes standard web links through Universal Links starting with version 7.0.15. Flutter intercepts these links and tells iOS that the app handled them successfully. Since Flutter claims the link, iOS never triggers the fallback to open the URL in Safari.
You can fix this in two ways.
Handle links in Dart
Use the url_launcher package to detect when a link points to an external domain. When your app receives a link that does not belong to your domain, tell the plugin to open it in an external application.
import 'package:url_launcher/url_launcher.dart';
void handleLink(String link) async {
Uri uri = Uri.parse(link);
if (uri.host != 'your-app-domain.com') {
await launchUrl(uri, mode: LaunchMode.externalApplication);
} else {
// Handle internal link
}
}
Intercept links in native iOS code
Modify your AppDelegate.swift file to check the URL before the Flutter engine receives it. Returning false for external domains allows iOS to open the link in Safari as intended.
override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL {
if let host = url.host, !host.contains("your-app-domain.com") {
return false
}
}
return super.application(application, continue: userActivity, restorationHandler: restorationHandler)
}
Comments
0 comments
Please sign in to leave a comment.