Flutter Web使用url_launcher在iOS15.8短信填充异常求助
iOS 15.8.2 上 url_launcher 唤起短信内容异常的解决方案
针对你遇到的问题——Flutter Web应用在iOS 15.8.2的iPhone7上唤起短信时,内容跑到号码栏而非内容栏,这是旧版iOS对SMS URI格式的解析兼容问题,和url_launcher、Flutter版本无关。以下是几个可行的解决方案:
1. 手动构造URI字符串并编码内容
旧版iOS的短信应用对Uri类自动生成的query参数格式解析存在问题,改成手动拼接URI并对短信内容编码,能适配旧系统的解析逻辑:
void sendSMS({required String phone, required String password, required String command}) async { if (password.isNotEmpty) { String message = '*$password*$command'; // 手动构造sms链接,对body内容做URI编码 final String smsUrl = 'sms:$phone?body=${Uri.encodeComponent(message)}'; final Uri url = Uri.parse(smsUrl); if (await canLaunchUrl(url)) { await launchUrl(url); } else { Get.snackbar( 'error', 'error happend.', snackPosition: SnackPosition.BOTTOM, ); } Get.back(); } else { Get.snackbar( 'no password found', 'no password found.', ); } }
2. 尝试使用smsto scheme替代sms
部分旧iOS版本对smsto scheme的支持更稳定,替换scheme后可能解决解析异常:
final String smsUrl = 'smsto:$phone?body=${Uri.encodeComponent(message)}';
3. 验证URI格式正确性
可以先在iPhone7的Safari浏览器中直接输入构造好的sms链接(比如sms:123456?body=*test*cmd),测试是否能正确唤起短信并填充内容,以此确认是URI格式的问题而非Flutter代码逻辑问题。
内容的提问来源于stack exchange,提问作者milad
相关产品推荐
相关产品推荐

