Sunday, May 17, 2026
HomeiOS Developmentios - Is it doable to make audio file (m4a) workable with...

ios – Is it doable to make audio file (m4a) workable with UNNotificationAttachment (Native notification)?

[ad_1]

I noticed UNNotificationAttachment does present assist on each picture and audio.

Based mostly on https://developer.apple.com/documentation/usernotifications/unnotificationattachment

Create a UNNotificationAttachment object if you need to embrace
audio, picture, or video content material collectively in an alert-based
notification.

Therefore, I attempt to create 2 native notification (not push notification), which triggered by time. 1 notification has a picture, one other notification has an audio file (m4a)

Nonetheless, I discover the picture attachment does work properly. It’s displaying as thumbnail on proper.

However, there may be nothing proven for the audio file attachment. I count on there shall be an audio play button on proper.

This is how they appear like

enter image description here

Am I doing one thing incorrect? Or, my expectation is improper for the native notification’s UNNotificationAttachment?

This is my code which is utilizing UNNotificationAttachment

if let attachment = litePlainNote.attachmentables.first {
    supply = attachment.url
    identifier = "(timestamp)-(attachment.identify)"
} else if let recording = litePlainNote.recordingables.first {
    supply = recording.url
    identifier = "(timestamp)-(recording.identify)"
}

if let supply = supply, let identifier = identifier {
    let vacation spot = UserDataDirectory.notification.url.appendingPathComponent(identifier)
    do {
        strive FileManager.default.copyItem(at: supply, to: vacation spot)
        let notificationAttachment = strive UNNotificationAttachment(identifier: identifier, url: vacation spot)
        content material.attachments.append(notificationAttachment)
    } catch {
        error_log(error)
    }
}

Might I do know can you make audio file (m4a) workable with UNNotificationAttachment (Native notification)?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments