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?
Question
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?
Solution
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:
- (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?