// in .m file -(void)textClicked { controller = [[MFMessageComposeViewController alloc] init]; if([MFMessageComposeViewController canSendText]) { controller.body = @"Whatever you want"; controller.recipients = [NSArray arrayWithObjects:@"", nil]; controller.messageComposeDelegate = self; [self presentViewController:controller animated:YES completion:nil]; } } - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"Unknown Error" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; switch (result) { case MessageComposeResultCancelled: NSLog(@"Cancelled"); [alert show]; break; case MessageComposeResultFailed: [alert show]; break; case MessageComposeResultSent: break; default: break; } [self dismissViewControllerAnimated:YES completion:nil]; } // in .h file import MessageUI/MessageUI.h and delegate for Sending Message is MFMessageComposeViewControllerDelegate
Hope this helps you.
source share