如何解决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 举报,一经查实,本站将立刻删除。