Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

ios - SMS WatchKit multiple number delimiter

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...