ios - 在 SwiftUI 中使用 DropDelegate 获取项目的 URL
问题描述
我有一个符合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
输出是CONTAINS AN URL
,如果我在iPadOS
输出是CONTAINS AN IMAGE
。
问题是我需要访问creationDate
源 URL 的一些元数据(如 ),creationDate
如果输出是UIImage
. 如何通过 DropDelegate 访问 iPadOS/iOS 上的源 URL?或者......我怎样才能获得由UIImage
提供的创建日期DropDelegate
?
Xcode 13 | macOS 12 | iPadOS 15 | 斯威夫特 5.5 | SwiftUI 3.0
解决方案
推荐阅读
- python - 使用 networkx.algorithms.approximation.steinertree.steiner_tree 提取 Steiner 树时出错
- javascript - 使用 [true, 'true'].includes(someVariable) 检查值是否为真有缺点吗?
- python-3.x - 如何组合两个不同类型的数组并将它们作为列表
- java - 执行功能文件时控制台不显示任何打印输出
- ruby - 如何从 .each 的最后一个实例中删除一个字符
- python - 编写一个程序,提示用户输入名字和姓氏。然后程序打印姓氏和名字
- javascript - 订阅中的角度订阅:数据不会在视图中同时加载
- docker - 我想共享一个容器的 Docker 文件夹并指向另一个共享文件夹
- java - 有没有办法替换 groovy/java 中的类扩展?
- sql-server - 创建自定义 SQL Server 侦听器以连接到共享的 localdb 实例?