导入头文件
#import <MessageUI/MessageUI.h>
调用方法
if ([MFMessageComposeViewController canSendText]) {
// 判断一下是否支持发送短信,比如模拟器
MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
messageVC.recipients = @[@"10086"]; //需要发送的手机号数组
messageVC.body = @"短信内容短信内容短信内容短信内容短信内容";
messageVC.modalPresentationStyle = UIModalPresentationFullScreen;
messageVC.messageComposeDelegate = self; //指定代理
[vc presentViewController:messageVC animated:YES completion:nil];
} else {
[PublicHUD showStateText:@"设备不支持短信功能"];
}
代理方法
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
if (result == MessageComposeResultCancelled) {
[controller dismissViewControllerAnimated:YES completion:nil];
} else if (result == MessageComposeResultFailed) {
[controller dismissViewControllerAnimated:YES completion:^{
[PublicHUD showStateText:@"邀请发送失败,请稍后重试"];
}];
} else {
[controller dismissViewControllerAnimated:YES completion:^{
[PublicHUD showStateText:@"邀请发送成功"];
}];
}
}