//1-头部
#import <MessageUI/MessageUI.h>
@interface ILShareViewController()<MFMessageComposeViewControllerDelegate>
@end
//2-点击分享部分
MFMessageComposeViewController *vc = [[MFMessageComposeViewController alloc] init];
// 设置短信内容
vc.body = @"吃饭了没?";
// 设置收件人列表
vc.recipients = @[@"10010", @"02010010"];
// 设置代理
vc.messageComposeDelegate = self;
// 显示控制器
[self presentViewController:vc animated:YES completion:nil];
//发送短信
MFMessageComposeViewController *messageComposeViewController = [[MFMessageComposeViewController alloc] init];
// 设置短信内容
messageComposeViewController.recipients = @[@"131****6666"];
messageComposeViewController.messageComposeDelegate = self;
NSString *body = @"http://www.apple.com/iphone\n我是且行且珍惜_iOS,欢迎关注我!";
messageComposeViewController.body = body;
// 添加图片
[messageComposeViewController addAttachmentData:UIImageJPEGRepresentation(imageToShare, 1.0) typeIdentifier:@"image/png" filename:@"wang.png"];
// if([MFMessageComposeViewController canSendSubject]){
// //设置主题
// messageComposeViewController.subject = @"https://github.com/wslcmk";
// }
if ([MFMessageComposeViewController canSendText]) {
[self presentViewController:messageComposeViewController animated:YES completion:nil];
}
//3-代理
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
// 关闭短信界面
[controller dismissViewControllerAnimated:YES completion:nil];
if (result == MessageComposeResultCancelled) {
NSLog(@"取消发送");
} else if (result == MessageComposeResultSent) {
NSLog(@"已经发出");
} else {
NSLog(@"发送失败");
}
}
网友评论