2011-04-15 84 views
0

嗨 我正在申請。在我的應用程序中,用戶必須發送消息給他/她從聯繫人列表中選擇的號碼。如何在短信中添加號碼?

if([MFMessageComposeViewController canSendText]) 
    { 

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

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

這就是我寫的。但選定的數字在另一個ViewController中。怎麼可能?請幫幫我。 謝謝

+0

請說明您尋求離子更多..幫助我們幫助你! – Saurabh 2011-04-15 05:48:04

+0

我有ViewController名稱聯繫人。在該視圖控制器中,我們可以從聯繫人列表中選擇5個電話號碼。當我按發送按鈕時,消息應發送到選定的號碼。而這段代碼是另一個viewController。如何在controller.recipient中添加收件人? – Priya 2011-04-15 05:53:12

+0

您需要創建一個數組並將該數組傳遞給另一個視圖contorller ...並且您可以在另一個視圖控制器中使用該數組添加收件人。 – Saurabh 2011-04-15 05:54:54

回答

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 

更多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]; 
} 
+0

MFMessageComposeViewController * controller = [[[MFMessageComposeViewController alloc] init] autorelease]; – Priya 2011-04-15 05:54:03

+0

如果我直接在那裏寫數字,它會發送。但我不想這樣。我有ViewController名稱聯繫人。在該視圖控制器中,我們可以從聯繫人列表中選擇5個電話號碼。當我按發送按鈕時,消息應發送到選定的號碼。而這段代碼是另一個viewController。如何在controller.recipient中添加收件人? – Priya 2011-04-15 05:57:06

+0

@Akhila:查看更新的答案... – Jhaliya 2011-04-15 05:59:55