您好,我搜索一个简单的示例(Android 和 iOS)来使用此包发送短信
https://pub.dartlang.org/packages/url_launcher https://pub.dartlang.org/packages/url_launcher
在插件页面中,我只看到如何使用电话号码打开短信本机应用程序,但没有额外的消息
sms:<phone number>, e.g. sms:5550101234 Send an SMS message to <phone
number> using the default messaging app
在 Android 上完整sms:
支持 URI,您可以发送带有这样的正文的消息 (RFC5724 https://www.ietf.org/rfc/rfc5724.txt):
_textMe() async {
// Android
const uri = 'sms:+39 348 060 888?body=hello%20there';
if (await canLaunch(uri)) {
await launch(uri);
} else {
// iOS
const uri = 'sms:0039-222-060-888?body=hello%20there';
if (await canLaunch(uri)) {
await launch(uri);
} else {
throw 'Could not launch $uri';
}
}
}
On iOS https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/SMSLinks/SMSLinks.html#//apple_ref/doc/uid/TP40007899-CH7-SW1官方文档说你只能使用 The 的数字字段URI
.
相反作为康斯坦丁指出,如果您使用非标准URI
而不是以 and 开头查询字符串?
你用&
它仍然有效。这似乎是一个未记录的功能。
sms 方案用于启动消息应用程序。 URL 的格式
这种类型是“sms:”,其中 是可选参数
指定 SMS 消息的目标电话号码。这
参数可以包含数字 0 到 9 以及加号 (+)、连字符
(-) 和句点 (.) 字符。URL 字符串不得包含任何
消息文本或其他信息.
附言。要检查您可以使用的平台dart.io 库Platform class https://api.dartlang.org/stable/1.24.3/dart-io/Platform-class.html:
_textMe() async {
if (Platform.isAndroid) {
const uri = 'sms:+39 348 060 888?body=hello%20there';
await launch(uri);
} else if (Platform.isIOS) {
// iOS
const uri = 'sms:0039-222-060-888&body=hello%20there';
await launch(uri);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)