Question

Flutter - detect whether the browser available or not in iOS

I know how to check browser availability in Android using the method channel. Is there any way we can detect whether the browser is available in an iPhone?

 3  36  3
1 Jan 1970

Solution

 0

You might want to look at url_launcher's canLaunchUrl:

Checks whether the specified URL can be handled by some app installed on the device.

Future<bool> isBrowserAvailable() async {
  const String testUrl = 'http://www.blablabal.com';
  if (await canLaunch(testUrl)) {
    return true;
  } else {
    return false;
  }
}

To address your comment stating that you have turned of the browser, but it's still returning True:

If we look at url_launcher's implementation of canLaunchUrl for iOS, we can see it directly calls the native iOS method of canOpenURL:

https://github.com/flutter/plugins/blob/557d3284ac9dda32a1106bb75be8a23bdccd2f96/packages/url_launcher/url_launcher_ios/ios/Classes/FLTURLLauncherPlugin.m#L88


- (BOOL)canLaunchURL:(NSString *)urlString {
  NSURL *url = [NSURL URLWithString:urlString];
  UIApplication *application = [UIApplication sharedApplication];
  return [application canOpenURL:url];
}

So, there must be something on your device allowing it to open URLs. Perhaps another browser app is installed?

2024-07-03
MendelG