A media file associated with a notification.
- iOS 10.0+
- watchOS 3.0+
UNNotification object contains audio, image, or video content to display alongside the notification content. Your app always supplies attachments. For local notifications, the app adds attachments when creating the rest of the notification’s content. To add attachments to a remote notification, use a notification service extension to modify the notification content before it is delivered. For more information about implementing a notification service extension, see
You create attachments using the
init(identifier: method of this class. You must specify the contents of an attachment using a file on disk, and the file format must be one of the supported types. After creating the attachment, assign it to the
attachments property of your notification’s content object. (For remote notifications, you must do this from your service extension.)
The system validates the content of attached files before scheduling the corresponding notification request. If an attached file is corrupted, invalid, or of an unsupported file type, the notification request is not scheduled for delivery. Once validated, attached files are moved into the attachment data store so that they can be accessed by the appropriate processes. Attachments located inside an app’s bundle are copied instead of moved.
Supported File Types
Table 1 lists the types of files you can include as an attachment and the supported file formats. The table also lists the maximum size allowed for attachments of each type. An image file may contain a static image or an animated image sequence.
When creating an attachment, you can specify optional details about how to present the thumbnail image for the image or movie. Use the
UNNotification option to create a thumbnail image based on the specified rectangle of the original image. For animated images and movies, use the
UNNotification option to selection which frame to use for the thumbnail image.
The amount of storage space allocated for attachments is limited for each app. To delete attachments, use the methods of the
UNUser class to remove the notification requests that contain those attachments.