#import <MessageUI/MessageUI.h>
//能否发送
if ( [MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController * sendVC = [[MFMessageComposeViewController alloc]init];
// 内容
sendVC.body = @"啦啦啦啦";
// 收件人,可单,可多
sendVC.recipients = @[@"10086",@"10010"];
// 代理(MFMessageComposeViewControllerDelegate)
sendVC.messageComposeDelegate = self;
[self presentViewController:sendVC animated:YES completion:nil];
}else{
NSLog(@"不能发送短信");
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
/*
取消
MessageComposeResultCancelled,
成功
MessageComposeResultSent,
失败
MessageComposeResultFailed
*/
}
如果不需要添加内容,并且给一个人发短信也可以用下面的方法
NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"sms://%@",@"10086"]];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}else{
NSLog(@"不能发短信");
}
网友评论