1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| //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];
//3-代理 - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { // 关闭短信界面 [controller dismissViewControllerAnimated:YES completion:nil]; if (result == MessageComposeResultCancelled) { NSLog(@"取消发送"); } else if (result == MessageComposeResultSent) { NSLog(@"已经发出"); } else { NSLog(@"发送失败"); } }
|