1
if (MFMessageComposeViewController.canSendText())
 { 
let controller = MFMessageComposeViewController()
controller.body = "" 
controller.recipients = ["1234567890"] 
controller.messageComposeDelegate = self as? MFMessageComposeViewControllerDelegate self.present(controller, animated: true, completion: nil) 
}  
 else
{ 
  print("Cannot send the message")
} 
func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) 
{ 
//Displaying the message screen with animation.
 self.dismiss(animated: true, completion: nil)
}

while sending sms i need to attach 2 pdf i know how to add on mail but for sms i haven't found any documentation. i have used this way for mail but how to do on messaging.

func sendEmail() {
        if MFMailComposeViewController.canSendMail() {
            let mail = MFMailComposeViewController()
            mail.mailComposeDelegate = self
            mail.setSubject("Invoice PDF")
            
            do {
                let attachmentData = NSData(contentsOfFile: pdfFilePath)
                mail.addAttachmentData(attachmentData! as Data, mimeType: "application/pdf", fileName: "InvoicePDF")
                mail.mailComposeDelegate = self
                present(mail, animated: true)
            }
            
        } else {
            // show failure alert
     }
}

  • https://stackoverflow.com/questions/39745761/sending-photo-using-mfmessagecomposeviewcontroller-is-disabled-in-ios10 with `addAttachmentData()`? – Larme Oct 13 '20 at 15:26

1 Answers1

0

You can export files using the UIActivityViewController:

let activityVC = UIActivityViewController(activityItems: [your-data-here], applicationActivities: nil) 
self.present(activityVC, animated: true, completion: nil)

If you want to limit the export options you can use the excludedActivityTypes property.

SteffenK
  • 582
  • 6
  • 17