swiftui - 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")
}
}
解决方案
推荐阅读
- docker - 即使使用 --restart=always,Docker 也不会重新启动容器
- groovy - Groovy List
- > behaving like List
- python - 使用列名作为 x 轴绘制熊猫数据框
- npm - NPM Workspaces 7 将包安装到工作空间/node_modules
- javascript - 为什么 UrlFetchApp.fetchAll() 执行后函数会失败?
- graphql - Strapi.JS GRAPHQL 错误“类型 \"StringFilterInput\" 的预期值,找到 \”anna\”。”,
- docker - 为什么 Bitbucket 管道给我一个 Sass 错误,说它找不到要导入的文件或文件不可读?
- excel - 如果上面的单元格被占用,则创建 If 语句
- google-apps-script - 是否有谷歌表格方法让编码公式每天在下一个空行中填充值?
- mysql - SQL UPDATE SET SELECT 慢