Files

49 lines
1.4 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// SendMail.swift
// PlusBank
//
// Created by Рустам Мотыгуллин on 08.06.2021.
//
import UIKit
import MessageUI
import SwiftLog
extension UIViewController {
func sendEmailLogs() {
if MFMailComposeViewController.canSendMail() {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["rustamburger@gmail.com"])
composeVC.setSubject("Send Email Logs")
composeVC.setMessageBody("", isHTML: false)
var attachmentData: NSData?
let path = Log.logger.currentPath
if FileManager.default.fileExists(atPath: path) {
if let data = NSData(contentsOfFile: path) {
attachmentData = data
}
}
guard let attData = attachmentData as Data? else { return }
composeVC.addAttachmentData(attData, mimeType: "text/plain", fileName: "crash.log")
self.present(composeVC, animated: true, completion: nil)
} else {
// Tell user about not able to send email directly.
}
}
}
extension UIViewController: MFMailComposeViewControllerDelegate {
public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
}
}