MFMessageComposeViewController

Important

This is a preliminary document for an API or technology in development. Apple is supplying this information to help you plan for the adoption of the technologies and programming interfaces described herein for use on Apple-branded products. This information is subject to change, and software implemented according to this document should be tested with final operating system software and final documentation. Newer versions of this document may be provided with future betas of the API or technology.

The MFMessageComposeViewController class provides a standard system user interface for composing text messages. Use this class to configure the initial recipients and body of the message, if desired, and to configure a delegate object to respond to the final result of the user’s action—whether they chose to cancel or send the message. After configuring initial values, present the view controller modally using the presentModalViewController:animated: method. When done, dismiss it using the dismissModalViewControllerAnimated: method.

Before presenting a message composition view, call the canSendText class method to ensure that the user’s device is appropriately configured. Do not attempt to present a message composition view if the canSendText method returns NOfalse. If neither iMessage nor SMS/MMS (Short Message Service/Multimedia Messaging Service) delivery is available, you can notify the user or simply disable the messaging features in your app.

The message composition interface itself is not customizable and must not be modified by your app. In addition, after presenting the interface, your app is unable to make further changes to the message content. The user can edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields, if desired, before presenting the interface

Returns a Boolean value indicating whether the current device is capable of sending text messages.

Declaration

Swift

classfunccanSendText() -> Bool

Objective-C

+ (BOOL)canSendText

Return Value

YEStrue if the device can send text messages or NOfalse if it cannot.

Discussion

Always call this method before attempting to present the message compose view controller. A device may be unable to send messages if it does not support messaging or if it is not currently configured to send messages. This method applies only to the ability to send text messages via iMessage, SMS, and MMS.

Declaration

Discussion

When the user taps a button to send or cancel the message, your delegate is notified and should respond by dismissing the message composition interface. For more information about implementing the methods of your delegate object, see MFMessageComposeViewControllerDelegate Protocol Reference.

The name to present to the user, in the message UI, for the data attachment.

Return Value

YEStrue if the attachment data was successfully added to the message, or NOfalse otherwise.

Discussion

This method is especially useful when the attachment you want to add to a message does not have a file system representation. This can be the case, for example, for programmatically composed audiovisual content.

Availability

See Also

Disables the camera/attachment button in the message composition view.

Declaration

Swift

funcdisableUserAttachments()

Objective-C

- (void)disableUserAttachments

Discussion

In iOS 7.0 and later, call this method to disable the camera/attachment button in the message composition view. In an app linked against an older version of iOS, the camera/attachment button is not available in any case.