情诗网 >情话短信 > 正文

swfit实现发短信及 MouMFMessageComposeV

来源:情诗网    2020-11-22    分类:情话短信

MouMFMessageComposeViewController属性及代理方法解释和使用

环境配置
注意:MessageUI.framework使用之前加入此库**

* 属性方法解释说明

* MFMessageComposeViewControllerDelegate 代理方法

- (void)messageComposeViewController:    (MFMessageComposeViewController *)controller

didFinishWithResult:(MessageComposeResult)result {
switch (result)
{
case MessageComposeResultCancelled:
LOG_EXPR(@”Result: SMS sending取消”);
break;
case MessageComposeResultSent:
LOG_EXPR(@”Result: SMS 发送成功”);
break;
case MessageComposeResultFailed:
[UIAlertView quickAlertWithTitle:@"短信发送失败" messageTitle:nil dismissTitle:@"关闭"];
break;
default:
LOG_EXPR(@”Result: SMS not sent”);
break;
}

使用步骤

在MessageUI.framework中主要有两个控制器类分别用于发送短信(MFMessageComposeViewController)和邮件(MFMailComposeViewController),它们均继承于UINavigationController。由于两个类使用方法十分类似,这里主要介绍一下MFMessageComposeViewController使用步骤:

代码实现:

 //Mark:- 发送短信
    func canSendText() -> Bool{
        return MFMessageComposeViewController.canSendText()
    }
    //用来指示一条消息能否从用户处发送
    func configuredMessageComposeViewController(phoneArray:Array<String>) -> MFMessageComposeViewController{
        
        let messageComposeVC = MFMessageComposeViewController()
        messageComposeVC.messageComposeDelegate = self
        messageComposeVC.body = HTTPREQUEST_NULLKEY
        messageComposeVC.recipients = phoneArray
        return messageComposeVC
    }
    
    func messageComposeViewController(controller: MFMessageComposeViewController, didFinishWithResult result: MessageComposeResult) {
        controller.dismissViewControllerAnimated(true, completion: nil)
    }
           if self.canSendText(){
                let messageVC = self.configuredMessageComposeViewController(["18611024550"])
                presentViewController(messageVC, animated: true, completion: nil)
            } else {
                MBProgressHUD.MBProgressHUDText("手机没有短信功能", showHUDView: self.view, delegate: self)
            }

热门文章