如何获取UIDocumentPickerViewController返回的URL的显示文件夹名称和应用程序图标?
这是我的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 :从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]
案例2 :从Dir
打开同一文档目录的子文件夹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
应用程序的文档,
这是本地文档的两种相同情况(目录/子目录):
案例3 :从PDF 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
的方法promisedItemResourceValues(forKeys:)
和.ubiquitousItemContainerDisplayNameKey
不适用于本地文件。
Documents
文件夹的应用程序的名称(与iCloud情况下displayName1
输出的结果相同)
UIDocumentPickerViewController
相同的应用图标? PS 我知道,通过将私有API用作LSApplicationWorkspace
,我可以使用提取的应用程序捆绑包ID(来自URL的XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB
)来获取应用程序的名称和图标,但需要一种公开的方式才能将我的应用提交到AppStore。
在此先感谢您的关注和帮助。