简体   繁体   English

试图在iOS 10中发送短信,“sms:”协议是否已损坏?

[英]Trying to send sms in iOS 10, Is “sms:” protocol broken?

I have a click-to-send-sms button. 我有一个click-to-send-sms按钮。

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;

They are telling me that it isn't working anymore in iOS 10, nothing happens when the button is clicked. 他们告诉我它在iOS 10中不再起作用,单击按钮时没有任何反应。 (the problem is not in the UA recognition, it goes into the "&body=...") (问题不在于UA识别,它进入“&body = ...”)

Currently I don't have an ios 10 device to debug... did they change the way to open the SMS outbox? 目前我没有ios 10设备进行调试......他们是否改变了打开短信发件箱的方式? Maybe I have to use encodeURIcomponent for the body like android/windows? 也许我必须使用encodeURIcomponent为身体像android / windows?

It seems not. 似乎没有。 Just tested this on my iPhone 6+ running iOS 10.0.1 刚在运行iOS 10.0.1的iPhone 6+上测试过

<!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>

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. 单击链接和按钮都完美地工作,打开消息应用程序与正确的数字,并将文本添加到正文。

Adding spaces, numbers and symbols works. 添加空格,数字和符号有效。 Although standard URI components apply (adding %20 adds a space for example). 虽然标准URI组件适用(例如,添加%20会添加空格)。 So I would recommend sanitising the body with encodeURIComponent . 所以我建议用encodeURIComponent消毒body


From what I can tell it seems Apple hasn't even updated their documentation on this : 据我所知,Apple似乎还没有更新他们的文档

The sms scheme is used to launch the Messages app. 短信方案用于启动消息应用程序。 The format for URLs of this type is “sms:”, where is an optional parameter that specifies the target phone number of the SMS message. 此类型的URL格式为“sms:”,其中是一个可选参数,用于指定SMS消息的目标电话号码。 This parameter can contain the digits 0 through 9 and the plus (+), hyphen (-), and period (.) characters. 此参数可以包含数字0到9以及加号(+),连字符( - )和句点(。)字符。 The URL string must not include any message text or other information. URL字符串不得包含任何消息文本或其他信息。

However, the body parameter is obviously working. 但是, body参数显然有效。

iOS < 7 <a href="sms:0412345678;body=text">send sms</a> iOS <7 <a href="sms:0412345678;body=text">send sms</a>
iOS > 7 <a href="sms:0412345678&body=text">send sms</a> iOS> 7 <a href="sms:0412345678&body=text">send sms</a>

After testing I've confirmed that <a href="sms:0412345678&body=test">send sms</a> works on: 经过测试,我已确认<a href="sms:0412345678&body=test">send sms</a>适用于:

  • iPhone 6+ (iOS 10.0.1) iPhone 6+(iOS 10.0.1)
  • iPhone 6 (iOS 10) iPhone 6(iOS 10)
  • iPhone 5 (iOS 9) iPhone 5(iOS 9)
  • iPhone 4S (iOS 8) iPhone 4S(iOS 8)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM