尝试在 iOS 10 中发送短信,"sms:" 协议是否损坏?
Trying to send sms in iOS 10, Is "sms:" protocol broken?
我有一个点击发送短信按钮。
现在我在单击按钮时使用此代码:
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=...")
目前我没有 ios 10 设备可以调试...他们是否更改了打开 SMS 发件箱的方式?也许我必须像 android/windows?
这样的正文使用 encodeURIcomponent
好像不是。刚刚在我的 iPhone 6+ 运行 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>
点击 link 和按钮都完美无缺,用正确的数字打开消息应用程序并将文本添加到正文。
添加 spaces、数字和符号有效。尽管标准 URI 组件适用(例如添加 %20
添加 space)。所以我建议用 encodeURIComponent
.
清理 body
据我所知,Apple 似乎还没有更新他们的 documentation on this:
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. This parameter can contain the digits 0 through 9 and the plus (+), hyphen (-), and period (.) characters. The URL string must not include any message text or other information.
但是,body
参数显然有效。
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>
适用于:
- iPhone 6+ (iOS 10.0.1)
- iPhone 6 (iOS 10)
- iPhone 5 (iOS 9)
- iPhone4S (iOS8)
我有一个点击发送短信按钮。
现在我在单击按钮时使用此代码:
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=...")
目前我没有 ios 10 设备可以调试...他们是否更改了打开 SMS 发件箱的方式?也许我必须像 android/windows?
这样的正文使用 encodeURIcomponent好像不是。刚刚在我的 iPhone 6+ 运行 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>
点击 link 和按钮都完美无缺,用正确的数字打开消息应用程序并将文本添加到正文。
添加 spaces、数字和符号有效。尽管标准 URI 组件适用(例如添加 %20
添加 space)。所以我建议用 encodeURIComponent
.
body
据我所知,Apple 似乎还没有更新他们的 documentation on this:
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. This parameter can contain the digits 0 through 9 and the plus (+), hyphen (-), and period (.) characters. The URL string must not include any message text or other information.
但是,body
参数显然有效。
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>
适用于:
- iPhone 6+ (iOS 10.0.1)
- iPhone 6 (iOS 10)
- iPhone 5 (iOS 9)
- iPhone4S (iOS8)