1,加入MessageUI.framework
2,XXViewController.h
#import "MessageUI/MessageUI.h"
@interface XXViewController : UIViewController <MFMessageComposeViewControllerDelegate>
3,XXViewController.m
- (void)sendMsg{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
controller.body = @"12345";
controller.recipients = [NSArray arrayWithObjects:@"", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
#pragma mark - MFMessageComposeViewControllerDelegate method
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
NSString *backMsg;
switch (result) {
case MessageComposeResultSent:
backMsg = @"Success";
break;
case MessageComposeResultCancelled:
backMsg = @"Cancelled";
break;
case MessageComposeResultFailed:
backMsg = @"Failure";
break;
default:
break;
}
NSLog(@"back %@", backMsg);
[self dismissModalViewControllerAnimated:YES];
}