Use following way :
// Add delegate in .h file
@interface ContactsViewController : UIViewController<MFMessageComposeViewControllerDelegate>
// Add this in your .m file
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
if(picker) {
picker.messageComposeDelegate = self;
picker.recipients = [NSArray arrayWithObject:number];
picker.body = @"body content";
[self presentViewController:picker animated:NO completion:nil];
picker = nil;
}
NSLog(@"SMS fired");
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
switch (result)
{
case MessageComposeResultCancelled:
NSLog(@"Result: canceled");
break;
case MessageComposeResultSent:
NSLog(@"Result: sent");
break;
case MessageComposeResultFailed:
NSLog(@"Result: failed");
break;
default:
NSLog(@"Result: not sent");
break;
}
//[self dismissModalViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
2
solved How do I send message programmatically in iPhone [closed]