1

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。

ご清聴ありがとうございました。

4

1 に答える 1