SwiftUI mailComposer 视图

问题描述

有没有办法在 SwiftUI MFMailComposeViewController 上启用附件功能?当显示在我的 SwiftUI 应用程序中时,它接受文本但不允许粘贴图像并且不显示用于添加附件的按钮。是否可以启用更完整的功能,更像是您通过 Apple 邮件或 Gmail 获得的完整标准邮件编辑器?谢谢

import Foundation
import UIKit
import MessageUI
import SwiftUI

struct MailView: UIViewControllerRepresentable {
    @EnvironmentObject var theBody: globalData
    var imageData: NoteImageData


    @Binding var isShowing: Bool
    @Binding var result: Result<MFMailComposeResult,Error>?

    class Coordinator: NSObject,MFMailComposeViewControllerDelegate {
   
        @Binding var isShowing: Bool
        @Binding var result: Result<MFMailComposeResult,Error>?

        init(isShowing: Binding<Bool>,result: Binding<Result<MFMailComposeResult,Error>?>) {
            _isShowing = isShowing
            _result = result
        }

        func mailComposeController(_ controller: 
        MFMailComposeViewController,didFinishWith result: 
        MFMailComposeResult,error: Error?) {
        defer {
            isShowing = false
        }
        guard error == nil else {
            self.result = .failure(error!)
            return
        }
        if result == MFMailComposeResult(rawValue: 2){
            print("sent")
            playSound(sound: "mailSent",type: "mp3")
        }
        if result == MFMailComposeResult(rawValue: 0){
            print("----------------> cancelled <----------------")
            
           
        }
       
        controller.dismiss(animated: true,completion: nil)
        //self.result = .success(result)
    }
}


func makeCoordinator() -> Coordinator {
    return Coordinator(isShowing: $isShowing,result: $result)
}

func makeUIViewController(context: 
    UIViewControllerRepresentableContext<MailView>) -> 
    MFMailComposeViewController {
    let vc = MFMailComposeViewController()
    vc.mailComposeDelegate = context.coordinator

    vc.setSubject("")
    //vc.setMessageBody(imageData.description,isHTML: true)
    vc.setMessageBody( theBody.mailBody,isHTML: true)
    
    self.theBody.mailSuccess = true
    theBody.mailBody = "" //12/26
 
    return vc
}

    func updateUIViewController(_ uiViewController: 
    MFMailComposeViewController,context: UIViewControllerRepresentableContext<MailView>) {
    print("==============> update UIviewController called")
 }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)