First you need to add the MessageUI framework to your project and import the "MessageUI/MessageUI.h" . Then execute the <MFMessageComposeViewControllerDelegate> protocol.
Now to send SMS:
- (IBAction) sendSMS:(id)sender { MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init]; if([MFMessageComposeViewController canSendText]) { controller.body = @"The body of the SMS you want"; controller.messageComposeDelegate = self; [self presentModalViewController:controller animated:YES]; } [controller release]; }
To catch the result of a send operation:
- (void) messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { switch(result) { case MessageComposeResultCancelled: break; //handle cancelled event case MessageComposeResultFailed: break; //handle failed event case MessageComposeResultSent: break; //handle sent event } [self dismissModalViewControllerAnimated:YES]; }
source share