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

# addAttachmentURL(_:withAlternateFilename:)

Attaches a specified file to the message.

```
func addAttachmentURL(_ attachmentURL: URL, withAlternateFilename alternateFilename: String?) -> Bool
```

## Parameters

`attachmentURL`

The file URL for the attachment. Must not be `nil`.

`alternateFilename`

If you supply a string here, the message UI uses it for the attachment. Use an alternate filename to better describe the attachment or to make the name more readable.

    OK to use a     `nil`     value, in which case the attachment’s actual filename is displayed in the message UI.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the attachment at the specified URL was successfully added to the message, or <doc://com.apple.documentation/documentation/Swift/false> otherwise.

## Discussion

You can add zero or more attachments to a message before you display the message to the user. To access information about a message’s attachments, access the [`attachments`](/documentation/MessageUI/MFMessageComposeViewController/attachments) property.

---

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)