#import <MessageUI/MessageUI.h>
@interface ViewController ()< MFMessageComposeViewControllerDelegate >
- (void)viewDidLoad
{
[super viewDidLoad];
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *mc =[[MFMessageComposeViewController alloc]init];
mc.messageComposeDelegate=self;
mc.body=@"你好";
mc.recipients=[NSArray arrayWithObjects:@"10086", nil];
[self presentViewController:mc animated:YES completion:nil];
}else{
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"error" message:@"the current can not send SMS"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"cancell");
break;
case MessageComposeResultFailed:
NSLog(@"failed");
break;
case MessageComposeResultSent:
NSLog(@"sent");
break;
default:
break;
}
}