app内发送短信
程序员文章站
2022-05-31 10:42:10
...
#pragma mark 调用短信页面方法
- (IBAction)click:(UIButton *)sender {
[self showMessageView];
}
#pragma mark 短信页面方法
- (void)showMessageView {
if( [MFMessageComposeViewController canSendText] ) {
MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init]; //autorelease];
controller.recipients = [NSArray arrayWithObject:@"17301797581"]; //接收者手机号
controller.body = @"请直接将此条认证短信发送给我们,以完成手机安全绑定。(9qzkd27953ma)"; //预填内容
controller.messageComposeDelegate = self; //添加代理
// [self presentViewController:controller animated:YES completion:nil];
// [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"新消息"];//修改短信界面标题
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"该设备不支持短信功能"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"确定", nil];
[alert show];
}
}
#pragma mark 短信结果显示代理方法
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[controller dismissViewControllerAnimated:NO completion:nil];
if (result == MessageComposeResultCancelled) {
NSLog(@"取消发送");
} else if (result == MessageComposeResultSent) {
NSLog(@"已经发出");
} else {
NSLog(@"发送失败");
}
}