开发者

Can recipients sent to MFMessageComposeViewController be formatted to show name instead of phone number?

When sending email, if I set MFMailComposeViewController recipients using standard RFC822 recipient format with "name" , MFMailComposeViewController will format recipients in the view to show the names with the email addresses hidden. So doing this:

MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];

NSArray *recipients = [NSArray arrayWithObjects:
                           @"\"Bob Paulsen"\ <bob@gmail.com>", 
                           @"\"Sally"\ <sally@开发者_StackOverflowgmail.com>", nil
                      ];
[composer setToRecipients:recipients];

results in this:

Can recipients sent to MFMessageComposeViewController be formatted to show name instead of phone number?

My question is: Is there a magic format I can use to do the same thing in with SMS recipients in MFMessageComposeViewController? I tried using the same format as email but it includes all the text (name and number) in the recipient field. I've tried a few other permutations but so far haven't lucked onto a solution.


The only way to do this would be in add a new contact with the recipient number into the user's address book. See the ABAddressBookAddRecord function in the ABAddressBook framework.

However, make sure your users know that this is happening and are OK with it...


I'm using XCode 7.2 (Apple Swift Version 2.1.1) and the following code works for me (without the recipient's email address saved in my address book):

let picker = MFMailComposeViewController()    
let recipients = ["\"Name Here\" <email@domain.com>"]
picker.setToRecipients(recipients)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜