一、导入头文件
#import <MessageUI/MessageUI.h>
二、创建
@property (nonatomic,strong) MFMessageComposeViewController *picker;
三、初始化
if ([MFMessageComposeViewControllercanSendText]) {
self.picker = [[MFMessageComposeViewControlleralloc]init];
self.picker.messageComposeDelegate = self;
//推荐的电话号码
NSString *phoneNum =@"13986097929";
self.picker.recipients =@[phoneNum];
self.picker.body = [NSStringstringWithFormat:@"测试数据为%@",@"24355"];
self.picker.navigationBar.tintColor = [UIColor redColor];
[selfpresentViewController: self.pickeranimated:YEScompletion:nil];
}else{
}
四、代理方法处理
-(void)messageComposeViewController:(MFMessageComposeViewController*)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
caseMessageComposeResultSent:
NSLog(@"信息传送成功");
[selfdismissViewControllerAnimated:YES completion:nil];
break;
caseMessageComposeResultFailed:
NSLog(@"信息传送失败");
[self dismissViewControllerAnimated: YES completion:nil];
break;
caseMessageComposeResultCancelled:
NSLog(@"信息被用户取消传送");
[selfdismissViewControllerAnimated:YES completion:nil];
break;
default:
break;
}
}