iOS: Launching Messages app with multiple recipients

∥☆過路亽.° 提交于 2019-12-22 06:18:51

问题


I'm trying to set it up so my user can send a text to a group of people. Now with email it's simple, the URL scheme is just mailto://firstemail@email.com,secondemail@email.com which can then be used with the openURL method.

Naturally when it came to SMS I decided to try sms://2065555555,2061234567 however this doesn't work (it only adds the first number). After browsing Google a bit, I found some older threads claiming that texting to multiple recipients isn't possible using the URL method.

In order to send a message to multiple people, I've gone ahead and added MessageUI to my application, hooked up the MFMessageComposeViewControllerDelegate, and now I can send indeed send messages to multiple people at once. However only from within my own application, which is not what I want. I was hoping there'd be something in the framework that would allow me to take advantage of the multiple recipients functionality and then launch it in the default messenger, but I can't find anything that allows that.

So, in short, is there any possible way I can code my app to populate the default Messages app with multiple recipients?

Edit

Actually I'm certain there must be a way to do it, I just checked the app Cobook and they allow the user to select contacts then launch the Messages app sending a "New Group MMS".


回答1:


I realize this is a very old question - but I discovered the way to do it recently, and posted about it here:

SMS WatchKit multiple number delimiter

While this answer is watchkit specific, the url is really what you are asking about.

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




回答2:


Apple's documentation for the "sms://" URL scheme seems to indicate only one phone number is possible within that URL.

The easiest thing to do here is to continue using MFMessageComposeViewController (which has a look and feel really close to the default Messages.app that people use to send and receive SMS messages).

And MFMessageComposeViewController has a receipients property which is an array, which means you can have multiple destination phone numbers in your compose view.

Lastly, here is a related question which covers a lot of the same ground you're thinking about here.



来源:https://stackoverflow.com/questions/23820570/ios-launching-messages-app-with-multiple-recipients

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