![](/img/trans.png)
[英]Is it possible to force my app to fetch a new apple-app-site-association file?
[英]File types association with my app
我的應用程序能夠導出和導入txt文件。 我的.plist
中的CFBundleDocumentTypes
和UTExportedTypeDeclarations
如下:
<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 iCloud
從my app folder on iCloud
點擊完全相同的文件時, my app folder on iCloud
程序未列在"Import with ..."
菜單中。
通過my app folder on iCloud
說my 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下的以下屬性將影響您的應用在文件上下文中的顯示方式和方式:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.