将 Mail 和 SMS/MMS 代表都添加到 class 类型

Adding BOTH Mail and SMS/MMS delegates to class type

我有一个简单的应用程序。它通过电子邮件和 SMS/MMS 截图。

因为我有两个按钮,每个按钮执行两个不同的功能 - (1) 屏幕截图然后发送电子邮件;和 (2) 屏幕截图然后 SMS/MMS,我需要将这些添加到我的代码中的 class

目前...

import UIKit
import MessageUI


class ViewController: UIViewController, MFMailComposeViewControllerDelegate {

如何将 MFMessageComposeViewControllerDelegate 添加到上面的 class 语句中?

我想我需要,因为我有发送电子邮件和 SMS/MMS 的功能。

抱歉我的语言描述,我是新手:)

还要检查这个 link : check this link

import UIKit
import MessageUI

class ViewController: UIViewController, MFMessageComposeViewControllerDelegate, MFMailComposeViewControllerDelegate {

@IBOutlet weak var phoneNumber: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()
}

@IBAction func sendText(sender: UIButton) {
    if (MFMessageComposeViewController.canSendText()) {
        let controller = MFMessageComposeViewController()
        controller.body = "Message Body"
        controller.recipients = [phoneNumber.text]
        controller.messageComposeDelegate = self
        self.presentViewController(controller, animated: true, completion: nil)
    }
}


   func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
    //... handle sms screen actions
     self.dismissViewControllerAnimated(true, completion: nil)
    }

override func viewWillDisappear(animated: Bool) {
    self.navigationController?.navigationBarHidden = false
}

 @IBAction func sendMail(sender: UIButton)
 {
    let mailClass:AnyClass?  =NSClassFromString("MFMailComposeViewController")
   if(mailClass != nil)
   {
    if((mailClass?.canSendMail()) != nil)
    {
      displayComposerSheet()
    }
  }

  func displayComposerSheet()
  {
   let picker: MFMailComposeViewController=MFMailComposeViewController()
   picker.mailComposeDelegate=self;
   picker .setSubject("Test")
   picker.setMessageBody("Mail Sharing !", isHTML: true)
   let data: NSData = UIImagePNGRepresentation(UIImage(named: "images.jpg")!)!
   picker.addAttachmentData(data, mimeType: "image/png", fileName: "images.png")
   self.presentViewController(picker, animated: true, completion: nil)
  }


  func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
    switch result.rawValue {
    case MFMailComposeResultCancelled.rawValue:
        print("Mail cancelled")
    case MFMailComposeResultSaved.rawValue:
        print("Mail saved")
    case MFMailComposeResultSent.rawValue:
        print("Mail sent")
    case MFMailComposeResultFailed.rawValue:
        print("Mail sent failure: \(error!.localizedDescription)")
    default:
        break
    }
    controller.dismissViewControllerAnimated(true, completion: nil)
  }


 }