SwiftUIMessage

SwiftUIMessageUI 的封装。

文档

SwiftUIMessage 的文档托管在 Swift Package Index 上。

使用说明

请务必始终在线调用 MailComposeView.canSendMail()MessageComposeView.canSendText() 来确认您是否真的可以在该设备上使用它们。 并且如果不包含 .ignoresSafeArea() 视图修饰符,可能会出现图形故障。

通常最好在 .sheet() 修饰符中使用它们,但以下代码仅用于举例说明。

示例

MailComposeView

// This will return false if the device cannot use Apple Mail.
if MailComposeView.canSendMail() {
    MailComposeView(
        .init(subject: "Subject",
              toRecipients: [
                  "dummy@gmail.com"
              ],
              ccRecipients: nil,
              bccRecipients: nil,
              body: "This is an example email body.",
              bodyIsHTML: false,
              preferredSendingEmailAddress: nil)
    )
    .ignoresSafeArea()
} else {
    // Here you can tell the user the issue, or maybe launch the URL scheme to open the default mail app (which wouldn't be Apple Mail).
    Text("Mail cannot be sent from your device.")
}

MessageComposeView

if MessageComposeView.canSendText() {
    MessageComposeView(
        .init(recipients: [
                  "111-111-1111",
                  "+1-111-111-1112"
              ],
              subject: "This is an MMS subject line, but it won't be inlcuded if the device doesn't have them enabled.",
              body: "This is an SMS text body.")
    )
    .ignoresSafeArea()
} else {
    // Here you can tell the user the issue.
    Text("Text messages cannot be sent from your device.")
}