Compose mail and messages with the iOS system UI
One.iOS.MFMailComposeViewController and
One.iOS.MFMessageComposeViewController present Apple’s mail and message
composers. Check canSendMail() or canSendText() first. Simulators and devices
without configured services can report false. These are capability checks;
One does not replace an unavailable composer with another mail or SMS app.
import { One } from 'one'
if (One.iOS.MFMailComposeViewController.canSendMail()) { const composer = new One.iOS.MFMailComposeViewController() composer.setToRecipients(['hello@example.com']) composer.setSubject('Hello') composer.setMessageBody('A message from the app', false) composer.mailComposeDelegate = { mailComposeController: (controller, result) => { // result.didFinishWith: cancelled, saved, sent or failed. // result.error preserves NSError domain, code and localizedDescription. void controller.dismiss() }, } await composer.present()}
if (One.iOS.MFMessageComposeViewController.canSendText()) { const composer = new One.iOS.MFMessageComposeViewController() composer.recipients = ['+15555550100'] composer.body = 'Hello' composer.messageComposeDelegate = { messageComposeViewController: (controller, result) => { // result.didFinishWith: cancelled, sent or failed. void controller.dismiss() }, } await composer.present()}The native controller remains owned by its delegate until the app dismisses it.
present(animated = true) adapts UIViewController presentation to the current
app presenter and resolves after presentation. Delegate callbacks report the
composition result separately. dismiss(animated = true) resolves after
closing the controller. Swift delegate argument labels become a JavaScript
object after the controller argument.
Mail’s static canSendMail() returns the SDK capability. Message’s static
canSendText(), canSendAttachments() and canSendSubject() return SDK
capabilities; isSupportedAttachmentUTI(uti) checks an attachment type.
Attachments use ArrayBuffer for native Data and file URL strings for native
URL. Message attachment results preserve SDK success/failure booleans.
attachments exposes native attachment URL and alternate filename dictionaries
as { attachmentURL, attachmentAlternateFilename? } records.
| Mail controller | Type | Description |
|---|---|---|
mailComposeDelegateMFMailComposeViewControllerDelegate<MFMailComposeController> | nullReceives result and optional NSError fields. | MFMailComposeViewControllerDelegate<MFMailComposeController> | null | Receives result and optional NSError fields. |
setSubject(subject: string) => voidSets the mail subject. | (subject: string) => void | Sets the mail subject. |
setToRecipients(recipients: string[]) => voidSets primary recipients. | (recipients: string[]) => void | Sets primary recipients. |
setCcRecipients(recipients: string[]) => voidSets copied recipients. | (recipients: string[]) => void | Sets copied recipients. |
setBccRecipients(recipients: string[]) => voidSets blind copied recipients. | (recipients: string[]) => void | Sets blind copied recipients. |
setMessageBody(body: string, isHTML: boolean) => voidSets plain text or HTML body. | (body: string, isHTML: boolean) => void | Sets plain text or HTML body. |
setPreferredSendingEmailAddress(emailAddress: string) => voidSelects a preferred sending account. | (emailAddress: string) => void | Selects a preferred sending account. |
addAttachmentData(attachment: ArrayBuffer, mimeType: string, fileName: string) => voidAdds native bytes with MIME type and filename. | (attachment: ArrayBuffer, mimeType: string, fileName: string) => void | Adds native bytes with MIME type and filename. |
present(animated?: boolean) => Promise<void>Presents the configured system composer. | (animated?: boolean) => Promise<void> | Presents the configured system composer. |
dismiss(animated?: boolean) => Promise<void>Dismisses the system composer. | (animated?: boolean) => Promise<void> | Dismisses the system composer. |
| Message controller | Type | Description |
|---|---|---|
messageComposeDelegateMFMessageComposeViewControllerDelegate<MFMessageComposeController> | nullReceives completion or cancellation. | MFMessageComposeViewControllerDelegate<MFMessageComposeController> | null | Receives completion or cancellation. |
recipientsstring[] | undefinedRecipient addresses; undefined clears them. | string[] | undefined | Recipient addresses; undefined clears them. |
bodystring | undefinedMessage body; undefined clears it. | string | undefined | Message body; undefined clears it. |
subjectstring | undefinedSubject when supported; undefined clears it. | string | undefined | Subject when supported; undefined clears it. |
attachmentsMessageAttachment[]Native attachment URLs and alternate filenames. | MessageAttachment[] | Native attachment URLs and alternate filenames. |
disableUserAttachments() => voidDisables attachment insertion by the user. | () => void | Disables attachment insertion by the user. |
addAttachmentData( attachment: ArrayBuffer, typeIdentifier: string, filename: string ) => booleanAdds native bytes with a type identifier and filename. | ( attachment: ArrayBuffer, typeIdentifier: string, filename: string ) => boolean | Adds native bytes with a type identifier and filename. |
addAttachmentURL(attachmentURL: string, withAlternateFilename?: string) => booleanAdds a file URL with an optional display filename. | (attachmentURL: string, withAlternateFilename?: string) => boolean | Adds a file URL with an optional display filename. |
present(animated?: boolean) => Promise<void>Presents the configured system composer. | (animated?: boolean) => Promise<void> | Presents the configured system composer. |
dismiss(animated?: boolean) => Promise<void>Dismisses the system composer. | (animated?: boolean) => Promise<void> | Dismisses the system composer. |
Mail configuration requires a device on which mail can be sent. Unsupported
mail and message presentation reject with E_MAIL_COMPOSE_UNAVAILABLE and
E_MESSAGE_COMPOSE_UNAVAILABLE. Presentation without an active presenter
rejects with E_UIKIT_PRESENTER; duplicate presentation and overlapping
transitions reject with E_UIKIT_PRESENTED and E_UIKIT_TRANSITION.
The simulator fixture checks real capability results and unsupported presentation without a success callback. Actual supported composer content, attachment acceptance, sending, saving and user cancellation require device acceptance. A delegate callback injected by a probe proves callback routing only.
Edit this page on GitHub.