簡體   English   中英

文件類型與我的應用程序關聯

[英]File types association with my app

我的應用程序能夠導出和導入txt文件。 我的.plist中的CFBundleDocumentTypesUTExportedTypeDeclarations如下:

<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>

導出按預期工作,沒有問題。 導入也很有效,但只適用於存儲在my app iCloud folder之外的my app iCloud folder ,即當我從郵件或通用iCloud文件夾中點擊.txt文件時,我可以在"Import with ..."菜單旁邊看到我的應用程序應用。 但是,當我my app folder on iCloudmy app folder on iCloud點擊完全相同的文件時, my app folder on iCloud程序未列在"Import with ..."菜單中。

通過my app folder on iCloudmy app folder on iCloud來澄清我的意思。 App具有使用以下功能在iCloud上導出和保存某些數據的功能:

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驅動器中創建app文件夾並將我的文件存儲在那里。 當我點擊這個文件時,我無法在"Import with ..."菜單中看到我的應用程序。 當我從app文件夾移出文件時,我的應用程序出現在"Import with ..."菜單中。

這是一個預期的設計和應用程序不希望“看到”他們自己的iCloud驅動器文件夾中的文件或我在.plist文件中缺少某種額外的文件關聯?

這是預期的行為,因為“導入”與“打開”不同。 通過導入文件,您可以將其內容作為應用數據的一部分。 您的應用程序中的文件iCloud容器已經是(部分)您的應用程序數據,因此將它們導入您的應用程序數據是沒有意義的。

UPDATE

CFBundleDocumentTypes下的以下屬性將影響您的應用在文件上下文中的顯示方式和方式:

  • CFBundleTypeRole的值:“編輯器”與“查看器” - 持久編輯需要將文件導入應用程序數據(此處“默認”不是有效值)
  • 已分配的LSHandlerRank :“所有者”,“默認”,“備用” - 聲明為文件類型的主要應用程序(所有者)可能導致“導入”部分被刪除
  • 注冊正確的LSItemContentTypes :“。csv”文件將被識別為“public.comma-separated-values-text”(kUTTypeCommaSeparatedText)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM