canLaunch is not launching URL in ios.But works fine in Android

371 views Asked by At

I am using canLaunchUrl to launch a UPI payment URL. This is working fine in Android but does not work in iOS. In iOS, they are not launching the URL instead they are moving to the else case and showing the toast message that we gave in the code. The UPI Url does not have any problem as we checked it separately. Moreover, canLaunchUrl works as it launches the phone number and email. Please help me to solve this problem.

Since canLaunch is deprecated I used canLaunchUrl and updated url_launcher to the latest version. But this too didn't work for me.

1

There are 1 answers

2
Urvashi kharecha On

You can launchUrl for example open map with URL from launch_url package:

Future<void> _launchUrl({double? originLat, double? originLng}) async {
        String url = Uri.encodeFull(
            'https://www.google.com/maps/search/?api=1&query=23.070907724512406,72.51759912698715');
    
        if (await canLaunchUrl(Uri.parse(url))) {
          await launchUrl(Uri.parse(url), webViewConfiguration: const WebViewConfiguration(enableJavaScript: true));
        } else {
          throw 'Could not launch $url';
        }
      }

And put following into your info.plist file

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>googlechromes</string>
        <string>comgooglemaps</string>
        <string>phonepe</string>
        <string>googlepay</string>
    </array>