【问题标题】:on click launch whastapp from flutter app in IOS点击从 IOS 中的颤振应用程序启动 wastapp
【发布时间】:2019-09-24 11:22:08
【问题描述】:

我正在尝试通过执行以下操作在点击时启动 WhatsApp:

var whatsAppUrl ="whatsapp://send?phone=+00000000";
  await canLaunch(whatsAppUrl)? launch(whatsAppUrl):Scaffold.of(context).showSnackBar(new SnackBar(
    content: new Text("You need WhatsApp to access"),
));

这在 android 中运行得非常好,但在 IOS 中却不行,我总是会在 IOS 中得到snackBar

如果它的 IOS,我也尝试将 url 更改为此:

whatsAppUrl = "https://api.whatsapp.com/send?phone=+00000‬";

但还是不行..我的网址有什么问题?

工作:

openWhatsApp() async {
    var whatsAppUrl = "whatsapp://send?phone=+00000‬";
    if (Platform.isIOS) {
      if (await canLaunch('whatsapp://')) {
        await launch(whatsAppUrl, forceSafariVC: false);
      } else {
        await launch(whatsAppUrl, forceSafariVC: true);
      }
    } else {
      await canLaunch(whatsAppUrl)
          ? launch(whatsAppUrl)
          : Scaffold.of(context).showSnackBar(
              SnackBar(
                content: new Text("You need WhatsApp to access Sara chatbot"),
              ),
            );
    }
  }

【问题讨论】:

    标签: ios flutter whatsapp


    【解决方案1】:

    尝试在 ios/Runnes/info.plist 中添加权限:

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

    【讨论】:

      【解决方案2】:

      似乎前一段时间 url_launcher 出现了一些问题,如果你有最新版本,你应该能够传递额外的参数 forceSafariVC 如果你想处理深层链接,应该在 ios 上设置为 false,我也是认为 canLaunch 应该只调用 url 方案前缀,如 await canLaunch('whatsapp://')

      来源:https://github.com/flutter/flutter/issues/25991

      【讨论】:

      • 非常感谢!我会用有效的答案更新我的帖子
      猜你喜欢
      • 2020-11-28
      • 2021-08-23
      • 1970-01-01
      • 2019-10-11
      • 1970-01-01
      • 2021-07-30
      • 2019-03-26
      • 2021-05-26
      • 1970-01-01
      相关资源
      最近更新 更多