如何获取 UIDocumentPickerViewController 返回的 URL 的显示文件夹名称和 App 图标?
这是我的Swift操场代码示例和下面的一些调试打印输出:
if let newUrl = urlFromPicker {
// 1
print("[DEBUG] newUrl: [\(newUrl)]")
// 2
let res = try! newUrl.promisedItemResourceValues(forKeys: [.ubiquitousItemContainerDisplayNameKey])
if let displayName1 = res.ubiquitousItemContainerDisplayName {
print("[DEBUG] newUrl displayName1: [\(displayName1)]")
}
// 3
if let displayName2 = FileManager.default.displayName(atPath: newUrl.absoluteString).removingPercentEncoding {
print("[DEBUG] newUrl displayName2: [\(displayName2)]")
}
}
案例 1:打开某个 App 的文件夹iCloud Drive(对于此示例PDF Viewer):
[DEBUG] newUrl: [file:///private/var/mobile/Library/Mobile%20Documents/iCloud~com~pspdfkit~viewer/Documents/]
[DEBUG] newUrl displayName1: [PDF Viewer]
[DEBUG] newUrl displayName2: [Documents]
案例 2Dir :从以下位置打开同一文档目录的子文件夹iCloud Drive:
[DEBUG] newUrl: [file:///private/var/mobile/Library/Mobile%20Documents/iCloud~com~pspdfkit~viewer/Documents/Dir/]
[DEBUG] newUrl displayName1: [PDF Viewer]
[DEBUG] newUrl displayName2: [Dir]
PDF Viewer由于我的设备上的相同应用程序中的文档也很少On My iPhone,因此本地文档有两种相同的情况(目录/子目录):
案例 3PDF Viewer :打开来自的本地文件夹On My iPhone:
[DEBUG] newUrl: [file:///private/var/mobile/Containers/Data/Application/XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB/Documents/]
[DEBUG] newUrl displayName2: [Documents]
案例 4:本地子文件夹:
[DEBUG] newUrl: [file:///private/var/mobile/Containers/Data/Application/XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB/Documents/Subdir/]
[DEBUG] newUrl displayName2: [Subdir]
问题:
- 因为可以看到
URL's 方法不适用于本地文件promisedItemResourceValues(forKeys:)。.ubiquitousItemContainerDisplayNameKey如何获取应用程序的名称,该Documents文件夹用于本地文件(与displayName1iCloud 的 1/2 情况下的输出结果相同)? - 是否可以获得与显示相同的应用程序图标
UIDocumentPickerViewController?
PS我知道通过使用私有API,因为LSApplicationWorkspace我可以使用提取的应用程序包ID(XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB来自URL)来获取应用程序的名称和图标,但是需要一种公开的方式才能将我的应用程序提交给稍后的 AppStore。
提前感谢您的关注和帮助。