How can I access audio attachment from INSendMessageIntent

I'm trying to add Siri support to my app for sending voice messages. I've implemented INSendMessageIntentHandling in my main app target.

It looks like it's getting as far as recording the voice message and passing my intent handler an INSendMessageIntent with an audio attachment, but I'm not able to read the attachment file.

func handle(
  intent: INSendMessageIntent,
  completion: @escaping (INSendMessageIntentResponse) -> Void
) {
  if let attachment = intent.attachments?.first,
     let audioFile = attachment.audioMessageFile,
     let fileURL = audioFile.fileURL
  {
    // This branch runs
    // fileURL is "file:///var/mobile/tmp/SiriMessages/89F738F7-6092-439A-B4FA-2DD9A99F0EED.caf"
    let result = processMessageAudio(url: fileURL)
    completion(result)
    return
  }

  // This line isn't reached
  completion(.init(code: .failure, userActivity: nil))
}

private func processMessageAudio(url: URL) -> INSendMessageIntentResponse {
  var fileRef: ExtAudioFileRef?
  if url.startAccessingSecurityScopedResource() {
    logDebug("File access allowed")
  } else {
    // This branch runs
    logDebug("File access not allowed")
  }
  defer {
    url.stopAccessingSecurityScopedResource()
  }

  let openStatus = ExtAudioFileOpenURL(url as CFURL, &fileRef)
  // openStatus is -54 (kAudio_FilePermissionError)

  return INSendMessageIntentResponse(code: .failure, userActivity: nil)
}

I'm not sure what I'm missing. It looks like there should be an audio file, and Siri shows a preview of the audio for confirmation.

The error means the audio file is not accessible from your sandbox or the file / directory has permissions that prevent you from accessing it.

That makes sense, but how to I gain permissions to access the file? It's an attachment to the INSendMessageIntent that my app is handling, so there should be some way for my app to gain access to it, right?

How can I access audio attachment from INSendMessageIntent
 
 
Q