Shortcut action that should return a file deletes the file instead

I have an app intent that returns a file from inside the Sandbox.

With iOS 18 RC, the call to INFile results in the file being deleted, instead of the file being returned.

intentResponse.file = INFile(fileURL: fileURL, filename: fileName, typeIdentifier: nil)

This seems to happen if the file was created by an earlier Shortcut action that calls FileManager().copyItem(), but not for files created by other means.

I haven't found a reference in the developer documentation about INFile resulting in the file being deleted.

I can block FileManager() from deleting the file by setting its immutable attributes to true, but that prevents me from removing it later.

Update: As a fix, I have used:

if let urlData = try? Data(contentsOf: fileURL) {
     intentResponse.file = INFile(data: urlData, filename: fileName, typeIdentifier: nil)
}

but it's still frustrating to encounter such an unexpected behaviour.

...But INFile(data: urlData, ...) only works if urlData is smaller than 512 MB, so that's not a complete replacement.

I'm seeing similar behaviour and when files are deleted the preview of the returned file shows "The operation failed because Shortcuts couldn't convert from Text to NSString."

https://s3files.nyc3.digitaloceanspaces.com/ScreenRecording_09-17-2024%2020-32-46_1.MP4

My work-around has been to rewrite the SiriKit intents into AppIntents which requires @IntentParameterDependency and iOS 17 but because of weaknesses in CustomIntentMigratedAppIntent this makes the existing SiriKit intents unavailable to users on iOS 16: https://developer.apple.com/forums/thread/734252

Shortcut action that should return a file deletes the file instead
 
 
Q