问题描述
我有一个点击发送短信按钮.
I have a click-to-send-sms button.
现在,当单击按钮时,我正在使用以下代码:
Now I'm using this code when the button is clicked:
if (platform == 'iOS') {
if (version == 4 || version == 5 || version == 6 || version == 7) {
link = 'sms:' + serviceNumber + ';body=' + body;
} else {
link = 'sms:' + serviceNumber + '&body=' + body;
}
} else {
link = 'sms:' + serviceNumber + '?body=' + encodeURIComponent(body);
}
window.location.href = link;
他们告诉我,它在iOS 10中不再起作用,单击按钮后什么也没有发生. (问题不在UA识别中,而是出现在& body = ..."中)
They are telling me that it isn't working anymore in iOS 10, nothing happens when the button is clicked. (the problem is not in the UA recognition, it goes into the "&body=...")
当前我没有ios 10设备要调试...他们是否改变了打开SMS发件箱的方式?也许我必须像Android/Windows一样对身体使用encodeURIcomponent?
Currently I don't have an ios 10 device to debug... did they change the way to open the SMS outbox? Maybe I have to use encodeURIcomponent for the body like android/windows?
推荐答案
似乎没有.刚刚在运行iOS 10.0.1的iPhone 6+上进行了测试
It seems not. Just tested this on my iPhone 6+ running iOS 10.0.1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<a href="sms:0412345678&body=testing">send sms</a>
<button onclick="window.location.href = 'sms:0412345678&body=testing'">send sms</button>
</body>
</html>
单击链接和按钮都可以正常工作,打开具有正确数字的Messages应用程序并将文本添加到正文中.
Both clicking the link and the button worked perfectly, opened up the Messages app with the correct number and added the text to the body.
添加空格,数字和符号即可.尽管应用了标准URI组件(例如,添加%20
会添加一个空格).所以我建议用encodeURIComponent
消毒body
.
Adding spaces, numbers and symbols works. Although standard URI components apply (adding %20
adds a space for example). So I would recommend sanitising the body
with encodeURIComponent
.
据我所知,似乎苹果甚至还没有更新其有关此文件的文档:
From what I can tell it seems Apple hasn't even updated their documentation on this:
但是,body
参数显然可以正常工作.
However, the body
parameter is obviously working.
iOS< 7 <a href="sms:0412345678;body=text">send sms</a>
iOS> 7 <a href="sms:0412345678&body=text">send sms</a>
经过测试,我确认<a href="sms:0412345678&body=test">send sms</a>
可用于:
After testing I've confirmed that <a href="sms:0412345678&body=test">send sms</a>
works on:
- iPhone 6+(iOS 10.0.1)
- iPhone 6(iOS 10)
- iPhone 5(iOS 9)
- iPhone 4S(iOS 8)
这篇关于尝试在iOS 10中发送短信,是"sms:"协议坏了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!