如何在短信中添加数字?

时间:2011-04-15 05:36:20

标签: iphone

您好     我正在开发一个应用程序。在我的应用程序中,用户必须向他/她从联系人列表中选择的号码发送消息。

if([MFMessageComposeViewController canSendText])
    {

        controller.recipients = [NSArray arrayWithObjects:@"12345678", @"87654321",nil];

        controller.recipients=[NSArray arrayWithObjects:@"name"];
        controller.messageComposeDelegate = self;
        [self presentModalViewController:controller animated:YES];
    }

这就是我写的。但是选定的数字在另一个ViewController中。怎么可能?请帮我。 谢谢

1 个答案:

答案 0 :(得分:0)

HI,

使用以下代码......

//Assume messageController is your MFMessageComposeViewController instance
NSString* numbersToSendString = @"929292,929292,929292";
NSArray* numbersToSend = [numbersToSendString componentsSeparatedByString:@","];
NSLog(@"numbers:");
[numbersToSend enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL* stop){
  NSLog(" object %lu: %@", (unsigned long) idx, obj);
}];
[messageController setReceipients:numbersToSend];
// ... continue whatever

更多ON SO帖子 \

<强>编辑:

if([MFMessageComposeViewController canSendText])
{
 MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
 picker.messageComposeDelegate = self;
 NSString *bodyString = nil;

 NSString* numbersToSendString = @"929292,929292,929292";
 NSMutableArray* toRecipients = [numbersToSendString componentsSeparatedByString:@","];      
[picker setRecipients:(NSArray *)toRecipients];
[toRecipients release];

bodyString = [NSString stringWithFormat: @"Message body"];
[picker setBody:bodyString];

[self presentModalViewController:picker animated:YES];
    [picker release];
}