2015-12-21 64 views
0

我已經將聯繫號碼存儲在一個數組中,然後將該數組傳遞給消息控制器,如下面的代碼,並打印controller.recipients的值並顯示null。如何使用數組中的號碼發送短信?

MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init]; 
    NSArray *arr = [NSArray arrayWithArray:selContacts]; 
    controller.recipients = arr; 
NSLog(@"received:- %@",controller.recipients); 
controller.messageComposeDelegate = self; 
controller.body [email protected]"https://itunes.apple.com/in/app/Click Here to Download!"; 
    if([MFMessageComposeViewController canSendText]) 
    { 
     [self presentModalViewController:controller animated:YES]; 
    } 
+1

打印[NSArray的arrayWithArray:selContacts]是否有任何接觸? –

+0

您正在調試哪個設備? –

+0

是的,5〜6個觸點是有 –

回答

2
if(![MFMessageComposeViewController canSendText]) 
{ 
    UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [warningAlert show]; 
    return; 

} 
NSArray *recipents = @[@"+919999999999"]; 
NSString *message = @"Enter message here!"; 
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init]; 
messageController.messageComposeDelegate = self; 
[messageController setRecipients:recipents]; 
[messageController setBody:message]; 
// Present message view controller on screen 
[self presentViewController:messageController animated:YES completion:nil];