我有一个符合DropDelegate的SwiftUI视图,工作正常,以便从macOS和iPadOS的其他应用程序接收图像,但在两个操作系统的行为是非常不同的:
struct ContentView: View {?
var body: some View {
MyView {?... }
.onDrop(of: [.fileURL, .image], delegate: self)
}
}
DropDelegate实现是:
extension ContentView: DropDelegate {?
func performDrop(info: DropInfo) -> Bool {
// Debug implementation
if info.hasItemsConforming(to: [.image]) {?
print("CONTAINS AN IMAGE")
} else if info.hasItemsConforming(to: [.fileURL]) {?
print("CONTAINS AN URL")
}
}
}
如果我在macOS的输出是包含一个URL,如果我在iPadOS的输出是包含一个图像。
问题是,我需要访问源URL的一些元数据(如creationDate),如果输出是一个UIImage,我不能访问creationDate。如何通过DropDelegate访问iPadOS/iOS上的源URL ?还是……我如何获得一个由DropDelegate提供的UIImage的creationDate ?
Xcode 13 | macOS 12 | iPadOS 15 | Swift 5。5 | SwiftUI 3。0