Swift短信分享

前端之家收集整理的这篇文章主要介绍了Swift短信分享前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

功能:用于短信分享内容

//MARK: 短信
    // 调用方法
    func sendMessage() {
       if (self.canSendText()) {
            self.presentViewController(self.configuredMessageComposeViewController(),animated: true,completion: nil)
       } else {
            MPAlertView.showAlertView("当前设备不支持短信功能")
       }
    }

    // 是否能发送短信
    func canSendText() -> Bool {
        return MFMessageComposeViewController.canSendText()
    }

    func configuredMessageComposeViewController() -> MFMessageComposeViewController {
        let messageComposeVC = MFMessageComposeViewController()
        messageComposeVC.messageComposeDelegate = self // 设置代理,遵循代理方法
        let inviteCode = NSUserDefaults.standardUserDefaults().stringForKey(kInviteCode)
        messageComposeVC.body = "短信内容"
        return messageComposeVC
    }

    //MARK: MFMessageComposeViewControllerDelegate
    func messageComposeViewController(controller: MFMessageComposeViewController!,didFinishWithResult result: MessageComposeResult) {
        switch result.value {
        case 0:
            MPAlertView.showAlertView("取消发送")
            self.dismissViewControllerAnimated(true,completion: nil)

        case 1:
            MPAlertView.showAlertView("发送失败")
            self.dismissViewControllerAnimated(true,completion: nil)

        case 2:
            MPAlertView.showAlertView("发送成功")
            self.dismissViewControllerAnimated(true,completion: nil)

        default:
            controller.dismissViewControllerAnimated(true,completion: nil)
        }
        self.dismissViewControllerAnimated(true,completion: nil)
    }
原文链接:https://www.f2er.com/swift/325954.html

猜你在找的Swift相关文章