iOS发送短信的代码

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
    #pragma mark -发送短信  
    @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;  
        }  
    }  

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇: Java线程池例子

下一篇:最小二乘法求多次拟合