//
//  Created by Pierluigi Cifani on 18/02/2019.
//  Copyright © 2019 TheLeftBit. All rights reserved.
//

#if canImport(UIKit)
#if canImport(MessageUI)

import UIKit
import MessageUI

final public class MailComposerBehavior: NSObject, MFMailComposeViewControllerDelegate {
    public static let composer = MailComposerBehavior()
    
    public func mailViewController(email: String) -> UIViewController? {
        guard MFMailComposeViewController.canSendMail() else {
            return nil
        }
        let mailVC = MFMailComposeViewController()
        mailVC.mailComposeDelegate = self
        mailVC.setToRecipients([email])
        return mailVC
    }
    
    public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        controller.dismiss(animated: true, completion: nil)
    }
}

#endif
#endif

//
//  Created by Pierluigi Cifani on 18/02/2019.
//  Copyright © 2019 TheLeftBit. All rights reserved.
//

#if canImport(UIKit)
#if canImport(MessageUI)

import UIKit
import MessageUI

final public class MessageComposerBehavior: NSObject, MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate {
    public static let composer = MessageComposerBehavior()
    
    public func mailViewController(email: String) -> UIViewController? {
        guard MFMailComposeViewController.canSendMail() else {
            return nil
        }
        let mailVC = MFMailComposeViewController()
        mailVC.mailComposeDelegate = self
        mailVC.setToRecipients([email])
        return mailVC
    }

    public func smsViewController(phoneNumber: String) -> UIViewController? {
        guard MFMessageComposeViewController.canSendText() else {
            return nil
        }
        let smsVC = MFMessageComposeViewController()
        smsVC.messageComposeDelegate = self
        smsVC.recipients = [phoneNumber]
        return smsVC
    }

    public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        controller.dismiss(animated: true, completion: nil)
    }
    
    public func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {

        controller.dismiss(animated: true, completion: nil)
    }
}

#endif
#endif

Rename MailComposerBehavior to MessageComposerBehavior and add SMS compose
Rename MailComposerBehavior to MessageComposerBehavior and add SMS compose
