Have you tried setting shouldAllowToOpenInPlace to true?
Unfortunately, the shouldAllowToOpenInPlace flag doesn’t help solving my issue.
Setting that flag prevents the file from being copied by dragging it in Finder. Also, FileRepresentation doesn’t seem to be involved when passing a file URL to another app such as Safari.
It appears that other representations need to be provided as well.
For example, if I add ProxyRepresentation(exporting: \.fileURL.absoluteString) afterward, I can drop the item onto Safari’s Dock icon. However, dropping it onto Safari’s address bar passes the URL of the sandbox container instead, and dropping it onto Safari’s content view does not interact with the page at all.
struct FolderFindDraggedFile: Transferable, Identifiable {
var fileURL: URL
static var transferRepresentation: some TransferRepresentation {
FileRepresentation(exportedContentType: .data) { item in
SentTransferredFile(item.fileURL, allowAccessingOriginalFile: true)
}
.suggestedFileName(\.fileURL.lastPathComponent)
ProxyRepresentation(exporting: \.fileURL)
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: