Link file types to my application

My application is able to export and import txt files. CFBundleDocumentTypesand UTExportedTypeDeclarationsin mine .plist:

<key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeIconFiles</key>
            <array>
                <string>Icon60@2x</string>
            </array>
            <key>CFBundleTypeName</key>
            <string>CSV</string>
            <key>CFBundleTypeRole</key>
            <string>Default</string>
            <key>LSHandlerRank</key>
            <string>Default</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.text</string>
            </array>
        </dict>
    </array>

<key>UTExportedTypeDeclarations</key>
    <array>
        <dict>
            <key>UTTypeConformsTo</key>
            <array>
                <string>public.text</string>
            </array>
            <key>UTTypeDescription</key>
            <string>CSV</string>
            <key>UTTypeIdentifier</key>
            <string>public.text</string>
            <key>UTTypeTagSpecification</key>
            <dict>
                <key>public.filename-extension</key>
                <string>csv</string>
                <key>public.mime-type</key>
                <string>application/myApp</string>
            </dict>
        </dict>
    </array>

Exporting the work, as expected, no problem. Import also works well, but only with files that are stored outside my app iCloud folder, that is, when I click a .txt file from mail or the iCloud public folder, I see my application in the "Import with ..."menu next to other applications. But when I click the exact same file from my app folder on iCloud, my application does not appear in the menu "Import with ...".

To clarify what I mean by saying my app folder on iCloud. The application has the function of exporting and saving certain data in iCloud with the following function:

func autoExportToIcloudDrive(_ localFileURL:URL, fileNameST:String) {
        let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents").appendingPathComponent("\(fileNameST).csv");
        if iCloudDocumentsURL != nil {
            let olderFileURL = iCloudDocumentsURL?.appendingPathComponent(fileNameST);
            if FileManager.default.fileExists(atPath: olderFileURL!.path) {
                self.uniFunc.deleteFileAtPath(pathUrl: olderFileURL!);
            }
            do {
                try FileManager.default.copyItem(at: localFileURL, to: iCloudDocumentsURL!);
            } catch {
                let nserror = error as NSError;
                fatalError("\(nserror), \(nserror.userInfo)");
            }
        }
    }

iCloud . , "Import with ...". , "Import with ...".

, "" iCloud, - .plist?

+4
1

, "" "". , . . iCloud () , .

UPDATE

CFBundleDocumentTypes , :

  • CFBundleTypeRole: "" "" - ( " " )
  • LSHandlerRank: "", " ", "" - () " "
  • LSItemContentTypes: .csv "public.comma-separated-values-values-text" (kUTTypeCommaSeparatedText)
0

Source: https://habr.com/ru/post/1685799/


All Articles