With iPhone OS 4.0 and above we can send SMS right from within our application. Now our application can invoke the SMS composer screen just like we invoke the Mail composer screen. We need to invoke an instance of MFMessageComposeViewController and assign the delegate, recipients and body of the SMS. The code snippet is provided below:
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"A test message from http://www.macoscoders.com";
controller.recipients = [NSArray arrayWithObjects:@"9880182343",nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
The MFMessageComposeViewController invoking class can implement the below delegate method to know the result of the SMS sending operation.
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
You can download sample XCode project source here