You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter url_launcher调用iOS iMessage无法加载号码及内容问题

Fix for url_launcher SMS Issue on iOS

Root Causes

  • iOS URI Format Difference: Unlike Android, iOS requires the recipient number to be passed via the to query parameter instead of the URI path.
  • Double Encoding: Manually using Uri.encodeComponent on the body text while using queryParameters results in double encoding, which breaks the message content.
  • Missing Async/Await: Not awaiting launchUrl can lead to race conditions or unexpected behavior.

Corrected Code

First, import dart:io to detect the platform:

import 'dart:io';
import 'package:url_launcher/url_launcher.dart';

Adjust the button click handler to use platform-specific URI construction:

Future<void> sendSMS() async {
  const String phoneNumber = '3939393939';
  const String message = 'Example Subject & Symbols are allowed!';

  Uri smsLaunchUri;

  if (Platform.isIOS) {
    // iOS uses 'to' query parameter for recipient
    smsLaunchUri = Uri(
      scheme: 'sms',
      queryParameters: {
        'to': phoneNumber,
        'body': message,
      },
    );
  } else {
    // Android uses path for recipient
    smsLaunchUri = Uri(
      scheme: 'sms',
      path: phoneNumber,
      queryParameters: {
        'body': message,
      },
    );
  }

  if (await canLaunchUrl(smsLaunchUri)) {
    await launchUrl(smsLaunchUri);
  } else {
    throw 'Could not launch SMS';
  }
}

Additional Notes

  • Testing on Real Device: iOS Simulator has limited support for SMS functionality. For reliable testing, use a physical iOS device.
  • Info.plist Configuration: Your existing LSApplicationQueriesSchemes setup is correct and doesn't need changes.

内容的提问来源于stack exchange,提问作者watercroc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 03:35:10