SMS WatchKit multiple number delimiter

我只是一个虾纸丫 提交于 2019-11-28 11:53:13

问题


I'm having a little trouble getting my WatchKit App to pre-compose an SMS message to multiple recipients (via the Apple Watch message app).

    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)

My question is, if you have multiple phone numbers you want to send the message to from the watch, how do you delimit the values?

The SMS Links documentation entry does not explain delimiting to multiple recips from an NSURL.

I have tried:

NSURL(string: "sms:8888888888,9999999999&body=\(urlSafeBody)")

and

NSURL(string: "sms:8888888888;9999999999&body=\(urlSafeBody)")

but the message always shows up composed only to the first number.

Any help appreciated!

UPDATE: iOS: Launching Messages app with multiple recipients was linked in comments indicating that only one recipient is allowed in NSURL. This means I am trying to figure out any other way to send an SMS via watchkit... Not possible?


回答1:


I found an obscure page that gave me the answer. Turns out it is not documented by Apple anywhere I could find:

    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)
     }

The above version will open the messages app on the Apple Watch with multiple recipients pre-populated.

There are many pages that state it isn't possible, but it is. Hooray!

Thanks @petahchristian for the links, it led me down a google path to find this page.

UPDATE: for the sake of completeness - here is a related question I asked to get a fully functional multiple recipient pre-written sms from the watch to send. AppleWatch Messages URL works hard coded but not with variables



来源:https://stackoverflow.com/questions/36575727/sms-watchkit-multiple-number-delimiter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!