Haseeb Ahmad
Haseeb Ahmad

Reputation: 8730

Problem launching Whatsapp from flutter on IOS

Sending message through whatsapp in Flutter is not working on IOS. It works fine on Android but on IOS whatsapp is not launching. I tried 3 different ways but unsuccessful in all of them.

In Runner Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>whatsapp</string>
</array>

1) First I tried this way to send message via message

var whatsappUrl = "whatsapp://send?phone=$phone&text=$message";
  if (await canLaunch(whatsappUrl)) {
    await launch(whatsappUrl);
  } else {
    throw 'Could not launch $whatsappUrl';
  }

But it gives an exception on launching whatsapp

enter image description here

2) Second way I tried is found from this link this but it giving an error that page not found

String url() {
  if (Platform.isIOS) {
     return "whatsapp://wa.me/$phone/?text=${Uri.parse(message)}";
  } else {
     return "whatsapp://send?   phone=$phone&text=${Uri.parse(message)}";
  }
}

if (await canLaunch(url())) {
   await launch(url());
} else {
   throw 'Could not launch ${url()}';
}

3) last I tried to call whatsapp url

String message = 'Hi, I see your Ad on Yallamotor and I am interested in your car '+title;
if (Platform.isIOS) {
  await launch("https://wa.me/${phone}?text=${Uri.parse(message)}");
}

but it gives error on whatsapp like we couldn't find the page you are looking for

enter image description here

Upvotes: 3

Views: 1781

Answers (2)

Abdullah Khan
Abdullah Khan

Reputation: 1481

By default, launchUrl mode is LaunchMode.platformDefault which will open webview, if you want to open installed app change it to LaunchMode.externalApplication.

if (await canLaunchUrl(url)) {
   await launchUrl(url, mode: LaunchMode.externalApplication);
} else {
   throw 'Could not launch $url';
}

Upvotes: 0

Lal Krishna
Lal Krishna

Reputation: 16170

Whatsapp supports Universal URLs on iOS devices.

The format is:

https://wa.me/<number>?text=<urlencodedtext>

Examples:

Use: https://wa.me/15551234567

Don't use: https://wa.me/+001-(555)1234567

Probably you are calling this URL with incorrect format in number.

Refer Whatsapp FAQ for iOS, Android.

Upvotes: 4

Related Questions