- (void)SendMMS{
NSString * documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
[self saveImage:[self convertViewToImage:self.bgView] withFileName:@"rainy" ofType:@"png" inDirectory:documentsDirectoryPath];
if ([MFMessageComposeViewController canSendAttachments]) {
MFMessageComposeViewController * messageVC = [[MFMessageComposeViewController alloc]init];
//手机号
// messageVC.recipients = @[@"136"];
//发送的内容
messageVC.body = @"发送内容";
NSString * documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * path = [documentsDirectoryPath stringByAppendingPathComponent:@"rainy.png"];
if ([messageVC addAttachmentURL:[NSURL fileURLWithPath:path] withAlternateFilename:nil])
{
NSLog(@"添加成功");
}else{
NSLog(@"失败");
}
messageVC.messageComposeDelegate = self;
/** 取消按钮的颜色(附带,可不写) */
messageVC.navigationBar.tintColor = [UIColor redColor];
[self presentViewController:messageVC animated:YES completion:nil];
}else{
NSLog(@"模拟器不支持发送短信");
}
}
1.首先得先导入#import <MessageUI/MessageUI.h>
2.实现代理MFMessageComposeViewControllerDelegate
3.点击按钮加入上面的代码,这个只是用来发送截图,或者直接存在的图片文本
4.实现代理方法
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
/** 发送完信息就回到原程序*/
[self dismissViewControllerAnimated:YES completion:nil];
switch (result) {
case MessageComposeResultSent:
NSLog(@"发送成功");
break;
case MessageComposeResultFailed:
NSLog(@"发送失败");
break;
case MessageComposeResultCancelled:
NSLog(@"发送取消");
default:
break;
}
}