<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MessageUI",
  "identifier" : "/documentation/MessageUI/MFMessageComposeViewController",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Message UI"
    ],
    "preciseIdentifier" : "c:objc(cs)MFMessageComposeViewController"
  },
  "title" : "MFMessageComposeViewController"
}
-->

# MFMessageComposeViewController

A standard view controller whose interface lets the user compose and send SMS or MMS messages.

```
class MFMessageComposeViewController
```

## Overview

Use an [`MFMessageComposeViewController`](/documentation/MessageUI/MFMessageComposeViewController) object to display the standard message composition interface inside your app. Before presenting the interface, populate the fields with the set of initial recipients and the message you want to send. After presenting the interface, a person can edit your initial values before sending the message.

The composition interface doesn’t guarantee the delivery of your message; it only lets you construct the initial message and present it for a person’s approval. The person may opt to cancel the composition interface which discards the message and its contents. If the person opts to send the message, the Messages app takes on the responsibility of sending the message.

![a screenshot of the New Message screen, with a phone number in the To field and a short sentence in the composition text field.](images/com.apple.messageui/media-4288093@2x.png)

> Important:
> You must not modify the view hierarchy presented by this view controller. However, you can customize the appearance of the interface using the <doc://com.apple.documentation/documentation/UIKit/UIAppearance> protocol.

An alternate way to compose SMS messages is to create and open a URL that uses the `sms` scheme. URLs of that type go directly to the Messages app, which uses your URL to configure the message. For information about the structure of `sms` URLs, see [Apple URL Scheme Reference](https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899).

### Checking the availability of the composition interface

Before presenting the message compose view controller, always call the [`canSendText()`](/documentation/MessageUI/MFMessageComposeViewController/canSendText()) method to see if the person configured the current device to send messages. If the user’s device isn’t set up to send or receive messages, you can notify the user or disable the messaging features in your application. You shouldn’t attempt to use this interface if the [`canSendText()`](/documentation/MessageUI/MFMessageComposeViewController/canSendText()) method returns <doc://com.apple.documentation/documentation/Swift/false>. If messaging is available, you can also use the [`canSendAttachments()`](/documentation/MessageUI/MFMessageComposeViewController/canSendAttachments()) and [`canSendSubject()`](/documentation/MessageUI/MFMessageComposeViewController/canSendSubject()) methods to determine if those specific messaging features are available.

**Swift:**

```swift
if !MFMessageComposeViewController.canSendText() {
    print("SMS services are not available")
}
```

**Obj-C:**

```objc
if (![MFMessageComposeViewController canSendText]) {
   NSLog(@"Message services are not available.");
}
```

### Configuring and displaying the composition interface

After verifying that message services are available, you can create and configure the message composition view controller and then present it like any other view controller. Use the methods of this class to specify the message’s recipients and the contents of the message. If attachments or a subject line are supported, you can set values for them as well. The sample code below shows how to configure the composition interface and present it modally. Always assign a delegate to the [`messageComposeDelegate`](/documentation/MessageUI/MFMessageComposeViewController/messageComposeDelegate) property, because the delegate is responsible for dismissing the composition interface later. The delegate object must conform to the [`MFMessageComposeViewControllerDelegate`](/documentation/MessageUI/MFMessageComposeViewControllerDelegate) protocol.

**Swift:**

```swift
let composeVC = MFMessageComposeViewController()
composeVC.messageComposeDelegate = self
 
// Configure the fields of the interface.
composeVC.recipients = ["4085551212"]
composeVC.body = "Hello from California!"
 
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil)
```

**Obj-C:**

```objc
MFMessageComposeViewController* composeVC = [[MFMessageComposeViewController alloc] init];
composeVC.messageComposeDelegate = self;
 
// Configure the fields of the interface.
composeVC.recipients = @[@"14085551212"];
composeVC.body = @"Hello from California!";
 
// Present the view controller modally.
[self present:composeVC animated:YES completion:nil];
```

The message compose view controller isn’t dismissed automatically. When the user taps the buttons to send the message or cancel the interface, the message compose view controller calls the [`messageComposeViewController(_:didFinishWith:)`](/documentation/MessageUI/MFMessageComposeViewControllerDelegate/messageComposeViewController(_:didFinishWith:)) method of its delegate. Your implementation of that method must dismiss the view controller explicitly, as shown in the sample code below. You can also use this method to check the result of the operation.

**Swift:**

```swift
func messageComposeViewController(controller: MFMessageComposeViewController,
                                  didFinishWithResult result: MessageComposeResult) {
    // Check the result or perform other tasks.
    
    // Dismiss the message compose view controller.
    controller.dismissViewControllerAnimated(true, completion: nil)}
```

**Obj-C:**

```objc
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
                 didFinishWithResult:(MessageComposeResult)result {
   // Check the result or perform other tasks.    // Dismiss the message compose view controller.
   [self dismissViewControllerAnimated:YES completion:nil];}
```

For more information on how to present and dismiss view controllers, see [View Controller Programming Guide for iOS](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/index.html#//apple_ref/doc/uid/TP40007457).

### Detecting changes to the availability of messaging

Add an observer to the [`MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification`](/documentation/MessageUI/MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification) notification to get notified of changes to the messaging capabilities of the current device. The system delivers that notification to your observer when the status of messaging changes.

## Topics

### Responding to the view controller dismissal

[`messageComposeDelegate`](/documentation/MessageUI/MFMessageComposeViewController/messageComposeDelegate)

The delegate to which message-related notifications should be sent.

[`MFMessageComposeViewControllerDelegate`](/documentation/MessageUI/MFMessageComposeViewControllerDelegate)

An interface for responding to user interactions with a message compose view controller.

### Determining if message composition is available

[`canSendText()`](/documentation/MessageUI/MFMessageComposeViewController/canSendText())

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

[`canSendAttachments()`](/documentation/MessageUI/MFMessageComposeViewController/canSendAttachments())

Indicates whether or not messages can include attachments.

[`canSendSubject()`](/documentation/MessageUI/MFMessageComposeViewController/canSendSubject())

Indicates whether or not messages can include subject lines, according to the user’s configuration in Settings.

[`isSupportedAttachmentUTI(_:)`](/documentation/MessageUI/MFMessageComposeViewController/isSupportedAttachmentUTI(_:))

Indicates whether or not the message can accept a file, with the specified UTI, as an attachment.

### Setting the initial message information

[`recipients`](/documentation/MessageUI/MFMessageComposeViewController/recipients)

An array of strings that contains the initial recipients of the message.

[`subject`](/documentation/MessageUI/MFMessageComposeViewController/subject)

The initial subject of the message.

[`body`](/documentation/MessageUI/MFMessageComposeViewController/body)

The initial content of the message.

[`message`](/documentation/MessageUI/MFMessageComposeViewController/message)

A message object from your iMessage app extension.

### Managing attachments

[`disableUserAttachments()`](/documentation/MessageUI/MFMessageComposeViewController/disableUserAttachments())

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

[`attachments`](/documentation/MessageUI/MFMessageComposeViewController/attachments)

Returns an array of dictionaries that describe the properties of an attachment.

[`addAttachmentURL(_:withAlternateFilename:)`](/documentation/MessageUI/MFMessageComposeViewController/addAttachmentURL(_:withAlternateFilename:))

Attaches a specified file to the message.

[`addAttachmentData(_:typeIdentifier:filename:)`](/documentation/MessageUI/MFMessageComposeViewController/addAttachmentData(_:typeIdentifier:filename:))

Attaches arbitrary content to the message.

[`MFMessageComposeViewControllerAttachmentURL`](/documentation/MessageUI/MFMessageComposeViewControllerAttachmentURL)

The URL for the item that is attached to the message.

[`MFMessageComposeViewControllerAttachmentAlternateFilename`](/documentation/MessageUI/MFMessageComposeViewControllerAttachmentAlternateFilename)

The key for the alternate filename for the file-based item attached to the message.

[`insertCollaborationItemProvider(_:)`](/documentation/MessageUI/MFMessageComposeViewController/insertCollaborationItemProvider(_:))

### Handling notifications

[`MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification`](/documentation/MessageUI/MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification)

Posted when the value returned by the [`canSendText()`](/documentation/MessageUI/MFMessageComposeViewController/canSendText()) class method has changed.

[`MFMessageComposeViewControllerTextMessageAvailabilityKey`](/documentation/MessageUI/MFMessageComposeViewControllerTextMessageAvailabilityKey)

The value of this key is a number object that contains a Boolean value.

### Configuring device validation

[`setUPIVerificationCodeSendCompletion(_:)`](/documentation/MessageUI/MFMessageComposeViewController/setUPIVerificationCodeSendCompletion(_:))

Configures the instance of a view for Unified Payments Interface (UPI) device validation.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)