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]
ケース 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
ため、ローカル ドキュメントの同じ 2 つのケース (ディレクトリ/サブディレクトリ) を次に示します。
ケース 3PDF Viewer
: fromのローカル ドキュメント フォルダを開く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
ないことがわかります。ローカルファイルに使用されているフォルダーのアプリの名前を取得する方法( iCloud のケース 1/2 の出力Documents
と同じ結果)?displayName1
- 表示されているのと同じアプリのアイコンを取得することはできます
UIDocumentPickerViewController
か?
PSプライベートAPIをLSApplicationWorkspace
使用することで、アプリの名前とアイコンを取得するために(URLから)抽出されたアプリのバンドルIDを使用できることはわかっていXXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB
ますが、アプリを送信するにはパブリックな方法が必要です後でAppStore。
ご清聴ありがとうございました。