【发布时间】:2018-02-25 14:57:30
【问题描述】:
我的应用程序能够导出和导入 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 之外的文件,即当我从邮件或通用 iCloud 文件夹中点击 .txt 文件时,我可以在其他应用程序旁边的"Import with ..." 菜单中看到我的应用程序。但是当我从my app folder on iCloud 点按完全相同的文件时,我的应用程序未列在"Import with ..." 菜单中。
为了澄清我所说的my app folder on iCloud 的意思。应用程序具有将某些数据导出并保存在 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 ..." 菜单中看不到我的应用程序。当我将文件移出应用程序文件夹时,我的应用程序出现在 "Import with ..." 菜单中。
这是一个预期的设计,应用程序不应“看到”它们自己的 iCloud 驱动器文件夹中的文件,还是我在 .plist 文件中缺少某种附加文件关联?
【问题讨论】:
标签: ios swift icloud icloud-drive icloud-documents