发送短信或邮件

引入MessageFoundation框架


@interface ViewController ()

{
    UIAlertView *mfAlertview;//定义一个弹出框
}
   
   
-(void)showMessageViewController
{
    if( [MFMessageComposeViewController canSendText] )//判断是否能发短息
{
           
        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init];
        controller.recipients = [NSArray arrayWithObject:@"10010"];//接收人,可以有很多,放入数组
        controller.body = self.txYaoqingma.text;//短信内容,自定义即可
        controller.messageComposeDelegate = self;//注意不是delegate  
           
        [self presentViewController:controller animated:YES completion:nil];
           
        [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"发送短信"];//修改短信界面标题
    }
    else
    {
           
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"抱歉" message:@"短信功能不可用!" delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil, nil nil];
        [alert show];
    }
}
   
//短信发送成功后的回调
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [controller dismissViewControllerAnimated:YES completion:nil];
       
    switch (result)
    {
        case MessageComposeResultCancelled:
        {
            //用户取消发送
        }
            break;
            case MessageComposeResultFailed://发送短信失败
        {
            mfAlertview=[[UIAlertView alloc]initWithTitle:@"抱歉" message:@"短信发送失败" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil, nil nil];
               
            [mfAlertview show];
              
        }
            break;
        case MessageComposeResultSent:
        {
            mfAlertview=[[UIAlertView alloc]initWithTitle:@"恭喜" message:@"短信发送成功!" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil, nil nil];
               
            [mfAlertview show];
               
        }
            break;
        default:
            break;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值