#import "ViewController.h" #import <MessageUI/MessageUI.h> @interface ViewController ()<MFMessageComposeViewControllerDelegate> @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self showMessageView:[NSArray arrayWithObjects:@"13888888888",@"13999999999", nil] title:@"test" body:@"你是土豪麼,麼麼噠"]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body { if( [MFMessageComposeViewController canSendText] ) { MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init]; controller.recipients = phones; controller.navigationBar.tintColor = [UIColor redColor]; controller.body = body; controller.messageComposeDelegate = self; [self presentViewController:controller animated:YES completion:nil]; [[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面標題 } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"該設備不支持短信功能" delegate:nil cancelButtonTitle:@"肯定" otherButtonTitles:nil, nil]; [alert show]; } } #pragma mark delegate -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [self dismissViewControllerAnimated:YES completion:nil]; switch (result) { case MessageComposeResultSent: //信息傳送成功 break; case MessageComposeResultFailed: //信息傳送失敗 break; case MessageComposeResultCancelled: //信息被用戶取消傳送 break; default: break; } } @end