0

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.

Marian Klösler
  • 620
  • 8
  • 22
Geethu
  • 1

1 Answers1

1

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>
Urvashi kharecha
  • 625
  • 1
  • 9
  • 26
  • Can you please share the code for adding URL schema of googlepay and phonepe in info.plist file. – Geethu Jan 27 '23 at 06:47
  • Thank you, mam. Earlier I gave phonepe like this. But it didn't work. Can you please tell me how to invoke a upi URL using canLaunchUrl(). – Geethu Jan 30 '23 at 11:01