我在让我的 WatchKit 应用程序预先编写一条 SMS 消息给多个收件人时遇到了一些麻烦(通过 Apple Watch 消息应用程序)。
let messageBody = "hello test message"
let urlSafeBody = messageBody.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLHostAllowedCharacterSet())
if let urlSafeBody = urlSafeBody, url = NSURL(string: "sms:8888888888&body=\(urlSafeBody)") {
WKExtension.sharedExtension().openSystemURL(url)
我的问题是,如果您有多个电话号码要从 watch 向其发送消息,您如何分隔这些值?
SMS Links 文档条目没有解释从 NSURL 到多个 recips 的分隔。
我试过:
NSURL(string: "sms:8888888888,9999999999&body=\(urlSafeBody)")
和
NSURL(string: "sms:8888888888;9999999999&body=\(urlSafeBody)")
但消息总是显示为仅由第一个数字组成。
感谢任何帮助!
更新: iOS: Launching Messages app with multiple recipients在评论中链接表明 NSURL 中只允许一个收件人。这意味着我正在尝试找出通过 watchkit 发送 SMS 的任何其他方式……不可能吗?
最佳答案
我found an obscure page这给了我答案。事实证明,Apple 在我能找到的任何地方都没有记录它:
let urlSafeBody = messageBody.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLHostAllowedCharacterSet())
if let urlSafeBody = urlSafeBody, url = NSURL(string: "sms:/open?addresses=1-408-555-1212,1-408-555-2121,1-408-555-1221&body=\(urlSafeBody)") {
WKExtension.sharedExtension().openSystemURL(url)
}
上述版本将在 Apple Watch 上打开消息应用程序,并预先填充多个收件人。
有许多页面 声明这是不可能的,但它是。万岁!
感谢@petahchristian 提供的链接,它让我沿着谷歌路径找到了这个页面。
更新:为了完整起见 - 这是一个相关问题,我要求从 watch 中获取功能齐全的多收件人预写短信以发送。 AppleWatch Messages URL works hard coded but not with variables
关于ios - SMS WatchKit 多个数字分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36575727/