当主题或正文为中文时,iOS中的网址启动器异常

时间:2019-12-06 12:24:35

标签: flutter dart

以下代码可在android设备上运行,但在iOS设备上会引发异常

dynamic _sendEmail() async {
    String url = 'mailto:support@test.com?subject=请写以上这个线';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }
Could not launch mailto:support@k8sllc.com?subject=请写以上这个线

1 个答案:

答案 0 :(得分:0)

您应该对网址进行编码:

String url = Uri.encodeComponent('mailto:support@test.com?subject=请写以上这个线');

所以看起来像这样:

mailto%3Asupport%40test.com%3Fsubject%3D%E8%AF%B7%E5%86%99%E4%BB%A5%E4%B8%8A%E8%BF%99%E4%B8%AA%E7%BA%BF